本文整理匯總了Golang中github.com/raphael/goa.Service.HTTPHandler方法的典型用法代碼示例。如果您正苦於以下問題:Golang Service.HTTPHandler方法的具體用法?Golang Service.HTTPHandler怎麽用?Golang Service.HTTPHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa.Service
的用法示例。
在下文中一共展示了Service.HTTPHandler方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MountPreflightController
// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
router := service.HTTPHandler().(*httprouter.Router)
for _, res := range spec {
path := res.Path
if res.IsPathPrefix {
if strings.HasSuffix(path, "/") {
path += "*cors"
} else {
path += "/*cors"
}
}
var handle httprouter.Handle
handle, _, tsr := router.Lookup("OPTIONS", path)
if tsr {
if strings.HasSuffix(path, "/") {
path = path[:len(path)-1]
} else {
path = path + "/"
}
handle, _, _ = router.Lookup("OPTIONS", path)
}
if handle == nil {
h := func(ctx *goa.Context) error {
return ctx.Respond(200, nil)
}
router.OPTIONS(path, goa.NewHTTPRouterHandle(service, "CORS", "preflight", h))
}
}
}
示例2: MountBottleController
// MountBottleController "mounts" a Bottle resource controller on the given service.
func MountBottleController(service goa.Service, ctrl BottleController) {
router := service.HTTPHandler().(*httprouter.Router)
var h goa.Handler
h = func(c *goa.Context) error {
ctx, err := NewCreateBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Create(ctx)
}
router.Handle("POST", "/cellar/accounts/:accountID/bottles", goa.NewHTTPRouterHandle(service, "Bottle", "Create", h))
service.Info("mount", "ctrl", "Bottle", "action", "Create", "route", "POST /cellar/accounts/:accountID/bottles")
h = func(c *goa.Context) error {
ctx, err := NewDeleteBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Delete(ctx)
}
router.Handle("DELETE", "/cellar/accounts/:accountID/bottles/:bottleID", goa.NewHTTPRouterHandle(service, "Bottle", "Delete", h))
service.Info("mount", "ctrl", "Bottle", "action", "Delete", "route", "DELETE /cellar/accounts/:accountID/bottles/:bottleID")
h = func(c *goa.Context) error {
ctx, err := NewListBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.List(ctx)
}
router.Handle("GET", "/cellar/accounts/:accountID/bottles", goa.NewHTTPRouterHandle(service, "Bottle", "List", h))
service.Info("mount", "ctrl", "Bottle", "action", "List", "route", "GET /cellar/accounts/:accountID/bottles")
h = func(c *goa.Context) error {
ctx, err := NewRateBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Rate(ctx)
}
router.Handle("PUT", "/cellar/accounts/:accountID/bottles/:bottleID/actions/rate", goa.NewHTTPRouterHandle(service, "Bottle", "Rate", h))
service.Info("mount", "ctrl", "Bottle", "action", "Rate", "route", "PUT /cellar/accounts/:accountID/bottles/:bottleID/actions/rate")
h = func(c *goa.Context) error {
ctx, err := NewShowBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Show(ctx)
}
router.Handle("GET", "/cellar/accounts/:accountID/bottles/:bottleID", goa.NewHTTPRouterHandle(service, "Bottle", "Show", h))
service.Info("mount", "ctrl", "Bottle", "action", "Show", "route", "GET /cellar/accounts/:accountID/bottles/:bottleID")
h = func(c *goa.Context) error {
ctx, err := NewUpdateBottleContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Update(ctx)
}
router.Handle("PATCH", "/cellar/accounts/:accountID/bottles/:bottleID", goa.NewHTTPRouterHandle(service, "Bottle", "Update", h))
service.Info("mount", "ctrl", "Bottle", "action", "Update", "route", "PATCH /cellar/accounts/:accountID/bottles/:bottleID")
}
示例3: MountAccountController
// MountAccountController "mounts" a Account resource controller on the given service.
func MountAccountController(service goa.Service, ctrl AccountController) {
router := service.HTTPHandler().(*httprouter.Router)
var h goa.Handler
h = func(c *goa.Context) error {
ctx, err := NewCreateAccountContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Create(ctx)
}
router.Handle("POST", "/cellar/accounts", ctrl.NewHTTPRouterHandle("Create", h))
service.Info("mount", "ctrl", "Account", "action", "Create", "route", "POST /cellar/accounts")
h = func(c *goa.Context) error {
ctx, err := NewDeleteAccountContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Delete(ctx)
}
router.Handle("DELETE", "/cellar/accounts/:accountID", ctrl.NewHTTPRouterHandle("Delete", h))
service.Info("mount", "ctrl", "Account", "action", "Delete", "route", "DELETE /cellar/accounts/:accountID")
h = func(c *goa.Context) error {
ctx, err := NewShowAccountContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Show(ctx)
}
router.Handle("GET", "/cellar/accounts/:accountID", ctrl.NewHTTPRouterHandle("Show", h))
service.Info("mount", "ctrl", "Account", "action", "Show", "route", "GET /cellar/accounts/:accountID")
h = func(c *goa.Context) error {
ctx, err := NewUpdateAccountContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Update(ctx)
}
router.Handle("PUT", "/cellar/accounts/:accountID", ctrl.NewHTTPRouterHandle("Update", h))
service.Info("mount", "ctrl", "Account", "action", "Update", "route", "PUT /cellar/accounts/:accountID")
}
示例4: MountSeriesController
// MountSeriesController "mounts" a Series resource controller on the given service.
func MountSeriesController(service goa.Service, ctrl SeriesController) {
router := service.HTTPHandler().(*httprouter.Router)
var h goa.Handler
h = func(c *goa.Context) error {
ctx, err := NewCreateSeriesContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Create(ctx)
}
router.Handle("POST", "/congo/accounts/:accountID/series", goa.NewHTTPRouterHandle(service, "Series", "Create", h))
service.Info("mount", "ctrl", "Series", "action", "Create", "route", "POST /congo/accounts/:accountID/series")
h = func(c *goa.Context) error {
ctx, err := NewListSeriesContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.List(ctx)
}
router.Handle("GET", "/congo/accounts/:accountID/series", goa.NewHTTPRouterHandle(service, "Series", "List", h))
service.Info("mount", "ctrl", "Series", "action", "List", "route", "GET /congo/accounts/:accountID/series")
h = func(c *goa.Context) error {
ctx, err := NewShowSeriesContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Show(ctx)
}
router.Handle("GET", "/congo/accounts/:accountID/series/:seriesID", goa.NewHTTPRouterHandle(service, "Series", "Show", h))
service.Info("mount", "ctrl", "Series", "action", "Show", "route", "GET /congo/accounts/:accountID/series/:seriesID")
h = func(c *goa.Context) error {
ctx, err := NewUpdateSeriesContext(c)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Update(ctx)
}
router.Handle("PATCH", "/congo/accounts/:accountID/series/:seriesID", goa.NewHTTPRouterHandle(service, "Series", "Update", h))
service.Info("mount", "ctrl", "Series", "action", "Update", "route", "PATCH /congo/accounts/:accountID/series/:seriesID")
}
示例5: MountController
// MountController mounts the swagger spec controller under "/swagger.json".
func MountController(service goa.Service) {
service.Info("mount", "ctrl", "Swagger", "action", "Show", "route", "GET /swagger.json")
h := goa.NewHTTPRouterHandle(service, "Swagger", "Show", getSwagger)
service.HTTPHandler().(*httprouter.Router).Handle("GET", "/swagger.json", h)
}