本文整理汇总了Golang中github.com/goadesign/goa.Service.ServeMux方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.ServeMux方法的具体用法?Golang Service.ServeMux怎么用?Golang Service.ServeMux使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/goadesign/goa.Service
的用法示例。
在下文中一共展示了Service.ServeMux方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MountAccountController
// MountAccountController "mounts" a Account resource controller on the given service.
func MountAccountController(service goa.Service, ctrl AccountController) {
// Setup encoders and decoders. This is idempotent and is done by each MountXXX function.
tmp15 := goa.GobEncoderFactory()
service.SetEncoder(tmp15, false, "application/gob", "application/x-gob")
tmp16 := goa.JSONEncoderFactory()
service.SetEncoder(tmp16, true, "application/json")
tmp17 := goa.XMLEncoderFactory()
service.SetEncoder(tmp17, false, "application/xml", "text/xml")
tmp18 := goa.GobDecoderFactory()
service.SetDecoder(tmp18, false, "application/gob", "application/x-gob")
tmp19 := goa.JSONDecoderFactory()
service.SetDecoder(tmp19, true, "application/json")
tmp20 := goa.XMLDecoderFactory()
service.SetDecoder(tmp20, false, "application/xml", "text/xml")
// Setup endpoint handler
var h goa.Handler
mux := service.ServeMux()
h = func(c *goa.Context) error {
ctx, err := NewCreateAccountContext(c)
ctx.Payload = ctx.RawPayload().(*CreateAccountPayload)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Create(ctx)
}
mux.Handle("POST", "/cellar/accounts", ctrl.HandleFunc("Create", h, unmarshalCreateAccountPayload))
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)
}
mux.Handle("DELETE", "/cellar/accounts/:accountID", ctrl.HandleFunc("Delete", h, nil))
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)
}
mux.Handle("GET", "/cellar/accounts/:accountID", ctrl.HandleFunc("Show", h, nil))
service.Info("mount", "ctrl", "Account", "action", "Show", "route", "GET /cellar/accounts/:accountID")
h = func(c *goa.Context) error {
ctx, err := NewUpdateAccountContext(c)
ctx.Payload = ctx.RawPayload().(*UpdateAccountPayload)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Update(ctx)
}
mux.Handle("PUT", "/cellar/accounts/:accountID", ctrl.HandleFunc("Update", h, unmarshalUpdateAccountPayload))
service.Info("mount", "ctrl", "Account", "action", "Update", "route", "PUT /cellar/accounts/:accountID")
}
示例2: MountPreflightController
// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
for _, res := range spec {
path := res.Path
if res.IsPathPrefix {
if strings.HasSuffix(path, "/") {
path += "*cors"
} else {
path += "/*cors"
}
}
handle := service.ServeMux().Lookup("OPTIONS", path)
if handle == nil {
h := func(ctx *goa.Context) error {
return ctx.Respond(200, nil)
}
ctrl := service.NewController("cors")
service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("preflight", h, nil))
}
}
}
示例3: MountBottleController
// MountBottleController "mounts" a Bottle resource controller on the given service.
func MountBottleController(service goa.Service, ctrl BottleController) {
// Setup encoders and decoders. This is idempotent and is done by each MountXXX function.
tmp21 := goa.GobEncoderFactory()
service.SetEncoder(tmp21, false, "application/gob", "application/x-gob")
tmp22 := goa.JSONEncoderFactory()
service.SetEncoder(tmp22, true, "application/json")
tmp23 := goa.XMLEncoderFactory()
service.SetEncoder(tmp23, false, "application/xml", "text/xml")
tmp24 := goa.GobDecoderFactory()
service.SetDecoder(tmp24, false, "application/gob", "application/x-gob")
tmp25 := goa.JSONDecoderFactory()
service.SetDecoder(tmp25, true, "application/json")
tmp26 := goa.XMLDecoderFactory()
service.SetDecoder(tmp26, false, "application/xml", "text/xml")
// Setup endpoint handler
var h goa.Handler
mux := service.ServeMux()
h = func(c *goa.Context) error {
ctx, err := NewCreateBottleContext(c)
ctx.Payload = ctx.RawPayload().(*CreateBottlePayload)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Create(ctx)
}
mux.Handle("POST", "/cellar/accounts/:accountID/bottles", ctrl.HandleFunc("Create", h, unmarshalCreateBottlePayload))
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)
}
mux.Handle("DELETE", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Delete", h, nil))
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)
}
mux.Handle("GET", "/cellar/accounts/:accountID/bottles", ctrl.HandleFunc("List", h, nil))
service.Info("mount", "ctrl", "Bottle", "action", "List", "route", "GET /cellar/accounts/:accountID/bottles")
h = func(c *goa.Context) error {
ctx, err := NewRateBottleContext(c)
ctx.Payload = ctx.RawPayload().(*RateBottlePayload)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Rate(ctx)
}
mux.Handle("PUT", "/cellar/accounts/:accountID/bottles/:bottleID/actions/rate", ctrl.HandleFunc("Rate", h, unmarshalRateBottlePayload))
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)
}
mux.Handle("GET", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Show", h, nil))
service.Info("mount", "ctrl", "Bottle", "action", "Show", "route", "GET /cellar/accounts/:accountID/bottles/:bottleID")
h = func(c *goa.Context) error {
ctx, err := NewUpdateBottleContext(c)
ctx.Payload = ctx.RawPayload().(*UpdateBottlePayload)
if err != nil {
return goa.NewBadRequestError(err)
}
return ctrl.Update(ctx)
}
mux.Handle("PATCH", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Update", h, unmarshalUpdateBottlePayload))
service.Info("mount", "ctrl", "Bottle", "action", "Update", "route", "PATCH /cellar/accounts/:accountID/bottles/:bottleID")
}