本文整理匯總了Golang中github.com/raphael/goa.Service.NewController方法的典型用法代碼示例。如果您正苦於以下問題:Golang Service.NewController方法的具體用法?Golang Service.NewController怎麽用?Golang Service.NewController使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa.Service
的用法示例。
在下文中一共展示了Service.NewController方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
ctrl := service.NewController("cors")
router.OPTIONS(path, ctrl.NewHTTPRouterHandle("preflight", h))
}
}
}
示例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))
}
}
}
示例3: NewAccountController
// NewAccountController creates a account controller.
func NewAccountController(service goa.Service) AccountController {
return &AccountController{Controller: service.NewController("AccountController")}
}
示例4: NewBottleController
// NewBottleController creates a bottle controller.
func NewBottleController(service goa.Service) BottleController {
return &BottleController{Controller: service.NewController("BottleController")}
}
示例5:
return err
}
c.SetPayload(payload)
}
return nil
}
var err error
reader := strings.NewReader(reqBody)
request, err = http.NewRequest("POST", "/foo?filters=one&filters=two&filters=three", reader)
Ω(err).ShouldNot(HaveOccurred())
rw = new(TestResponseWriter)
params = url.Values{"id": []string{"42"}, "filters": []string{"one", "two", "three"}}
})
JustBeforeEach(func() {
ctrl := app.NewController(resName)
handleFunc = ctrl.HandleFunc(actName, handler, unmarshaler)
handleFunc(rw, request, params)
})
Describe("Respond", func() {
It("sets the context fields", func() {
Ω(ctx.Request()).Should(Equal(request))
Ω(ctx.Header()).Should(Equal(rw.Header()))
Ω(ctx.ResponseStatus()).Should(Equal(respStatus))
Ω(ctx.ResponseLength()).Should(Equal(len(respContent)))
p := ctx.Get("id")
Ω(p).Should(Equal("42"))
ps := ctx.GetMany("filters")
Ω(ps).Should(Equal([]string{"one", "two", "three"}))
var payload string
示例6:
})
Describe("Use", func() {
Context("with a valid middleware", func() {
var m goa.Middleware
BeforeEach(func() {
m = goa.RequestID()
})
JustBeforeEach(func() {
s.Use(m)
})
It("adds the middleware", func() {
ctrl := s.NewController("test")
Ω(ctrl.MiddlewareChain()).Should(HaveLen(1))
Ω(ctrl.MiddlewareChain()[0]).Should(BeAssignableToTypeOf(goa.RequestID()))
})
})
})
Describe("NewHTTPRouterHandle", func() {
const resName = "res"
const actName = "act"
var handler goa.Handler
const respStatus = 200
var respContent = []byte("response")
var httpHandle httprouter.Handle
var ctx *goa.Context
示例7: NewBottle
// NewBottle creates a bottle controller.
func NewBottle(service goa.Service) *BottleController {
return &BottleController{
Controller: service.NewController("Bottle"),
db: NewDB(),
}
}
示例8: MountController
// MountController mounts the swagger spec controller under "/swagger.json".
func MountController(service goa.Service) {
ctrl := service.NewController("Swagger")
service.Info("mount", "ctrl", "Swagger", "action", "Show", "route", "GET /swagger.json")
h := ctrl.NewHTTPRouterHandle("Show", getSwagger)
service.HTTPHandler().(*httprouter.Router).Handle("GET", "/swagger.json", h)
}
示例9: NewAccount
// NewAccount creates a account controller.
func NewAccount(service goa.Service) *AccountController {
return &AccountController{
Controller: service.NewController("Account"),
db: NewDB(),
}
}