diff --git a/core/descriptor.go b/core/descriptor.go index c5faf71..9d6b99d 100644 --- a/core/descriptor.go +++ b/core/descriptor.go @@ -276,6 +276,11 @@ func (f *FieldDescriptor) HttpMethodArgs() string { return utils.QuoteJoin(f.HttpMethods, ",") } +// JustUseContext whether just use context +func (f *FieldDescriptor) JustUseContext() bool { + return f.IsUseContext && len(f.InOuts) == 0 +} + // OrInOut in or out func (f *FieldDescriptor) OrInOut() bool { return f.In != nil || f.Out != nil diff --git a/examples/mirc/auto/api/site.go b/examples/mirc/auto/api/site.go index e0d38b8..a1455b7 100644 --- a/examples/mirc/auto/api/site.go +++ b/examples/mirc/auto/api/site.go @@ -77,8 +77,9 @@ type Site interface { MultiAttachments(*gin.Context) ManyResources(*gin.Context) AnyStaticks(*gin.Context) - Assets(*gin.Context) - SimpleUpload(*gin.Context) + Statics(*gin.Context) + Assets(*gin.Context, *LoginReq) mir.Error + SimpleUpload(*gin.Context, *LoginReq) (*LoginResp, mir.Error) FileUpload(*gin.Context) ImageUpload(*gin.Context) Logout(*LogoutReq) mir.Error @@ -117,21 +118,47 @@ func RegisterSiteServant(e *gin.Engine, s Site, m ...SiteChain) { // register routes info to router { h := append(cc.ChainMultiAttachments(), s.MultiAttachments) - router.Handle("OPTIONS", "/attachments", h...) - router.Handle("HEAD", "/attachments", h...) - router.Handle("GET", "/attachments", h...) + router.Handle("GET", "/attachments/:name/", h...) + router.Handle("OPTIONS", "/attachments/:name/", h...) + router.Handle("HEAD", "/attachments/:name/", h...) } { h := s.ManyResources - router.Handle("OPTIONS", "/resources", h) - router.Handle("HEAD", "/resources", h) - router.Handle("GET", "/resources", h) + router.Handle("OPTIONS", "/resources/:name/", h) + router.Handle("HEAD", "/resources/:name/", h) + router.Handle("GET", "/resources/:name/", h) } - router.Any("/staticks", s.AnyStaticks) - router.Handle("GET", "/assets", s.Assets) - router.Handle("POST", "/upload/simple", append(cc.ChainSimpleUpload(), s.SimpleUpload)...) - router.Handle("POST", "/upload/file", append(cc.ChainFileUpload(), s.FileUpload)...) - router.Handle("POST", "/upload/image", s.ImageUpload) + router.Any("/anystaticks/:name/", s.AnyStaticks) + router.Handle("GET", "/statics/:name/", s.Statics) + router.Handle("GET", "/assets/:name/", func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + req := new(LoginReq) + if err := s.Bind(c, req); err != nil { + s.Render(c, nil, err) + return + } + s.Render(c, nil, s.Assets(c, req)) + }) + router.Handle("POST", "/upload/simple/:name/", append(cc.ChainSimpleUpload(), func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + req := new(LoginReq) + if err := s.Bind(c, req); err != nil { + s.Render(c, nil, err) + return + } + resp, err := s.SimpleUpload(c, req) + s.Render(c, resp, err) + })...) + router.Handle("POST", "/upload/file/:name/", append(cc.ChainFileUpload(), s.FileUpload)...) + router.Handle("POST", "/upload/image/:name/", s.ImageUpload) router.Handle("POST", "/user/logout/", func(c *gin.Context) { select { case <-c.Request.Context().Done(): @@ -240,12 +267,16 @@ func (UnimplementedSiteServant) AnyStaticks(c *gin.Context) { c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedSiteServant) Assets(c *gin.Context) { +func (UnimplementedSiteServant) Statics(c *gin.Context) { c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedSiteServant) SimpleUpload(c *gin.Context) { - c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +func (UnimplementedSiteServant) Assets(c *gin.Context, req *LoginReq) mir.Error { + return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +} + +func (UnimplementedSiteServant) SimpleUpload(c *gin.Context, req *LoginReq) (*LoginResp, mir.Error) { + return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } func (UnimplementedSiteServant) FileUpload(c *gin.Context) { diff --git a/examples/mirc/auto/api/v1/site.go b/examples/mirc/auto/api/v1/site.go index 94cea2c..ac33e4d 100644 --- a/examples/mirc/auto/api/v1/site.go +++ b/examples/mirc/auto/api/v1/site.go @@ -54,18 +54,18 @@ func RegisterSiteServant(e *gin.Engine, s Site, m ...SiteChain) { // register routes info to router { h := append(cc.ChainMultiAttachments(), s.MultiAttachments) - router.Handle("OPTIONS", "/attachments", h...) - router.Handle("HEAD", "/attachments", h...) - router.Handle("GET", "/attachments", h...) + router.Handle("OPTIONS", "/attachments/:name/", h...) + router.Handle("HEAD", "/attachments/:name/", h...) + router.Handle("GET", "/attachments/:name/", h...) } { h := s.ManyResources - router.Handle("OPTIONS", "/resources", h) - router.Handle("HEAD", "/resources", h) - router.Handle("GET", "/resources", h) + router.Handle("GET", "/resources/:name/", h) + router.Handle("OPTIONS", "/resources/:name/", h) + router.Handle("HEAD", "/resources/:name/", h) } - router.Any("/staticks", s.AnyStaticks) - router.Handle("GET", "/assets", s.Assets) + router.Any("/anystaticks/:name/", s.AnyStaticks) + router.Handle("GET", "/assets/:name/", s.Assets) router.Handle("POST", "/user/logout/", func(c *gin.Context) { select { case <-c.Request.Context().Done(): diff --git a/examples/mirc/auto/api/v2/site.go b/examples/mirc/auto/api/v2/site.go index 11a4fc3..3e01412 100644 --- a/examples/mirc/auto/api/v2/site.go +++ b/examples/mirc/auto/api/v2/site.go @@ -69,8 +69,8 @@ type Site interface { MultiAttachments(*gin.Context) ManyResources(*gin.Context) AnyStaticks(*gin.Context) - Assets(*gin.Context) - SimpleUpload(*gin.Context) + Assets(*gin.Context, *LoginReq) mir.Error + SimpleUpload(*gin.Context, *LoginReq) (*LoginResp, mir.Error) FileUpload(*gin.Context) ImageUpload(*gin.Context) Logout() mir.Error @@ -105,21 +105,46 @@ func RegisterSiteServant(e *gin.Engine, s Site, m ...SiteChain) { // register routes info to router { h := append(cc.ChainMultiAttachments(), s.MultiAttachments) - router.Handle("OPTIONS", "/attachments", h...) - router.Handle("HEAD", "/attachments", h...) - router.Handle("GET", "/attachments", h...) + router.Handle("HEAD", "/attachments/:name/", h...) + router.Handle("GET", "/attachments/:name/", h...) + router.Handle("OPTIONS", "/attachments/:name/", h...) } { h := s.ManyResources - router.Handle("OPTIONS", "/resources", h) - router.Handle("HEAD", "/resources", h) - router.Handle("GET", "/resources", h) + router.Handle("OPTIONS", "/resources/:name/", h) + router.Handle("HEAD", "/resources/:name/", h) + router.Handle("GET", "/resources/:name/", h) } - router.Any("/staticks", s.AnyStaticks) - router.Handle("GET", "/assets", s.Assets) - router.Handle("POST", "/upload/simple", append(cc.ChainSimpleUpload(), s.SimpleUpload)...) - router.Handle("POST", "/upload/file", append(cc.ChainFileUpload(), s.FileUpload)...) - router.Handle("POST", "/upload/image", s.ImageUpload) + router.Any("/anystaticks/:name/", s.AnyStaticks) + router.Handle("GET", "/assets/:name/", func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + req := new(LoginReq) + if err := s.Bind(c, req); err != nil { + s.Render(c, nil, err) + return + } + s.Render(c, nil, s.Assets(c, req)) + }) + router.Handle("POST", "/upload/simple/:name/", append(cc.ChainSimpleUpload(), func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + req := new(LoginReq) + if err := s.Bind(c, req); err != nil { + s.Render(c, nil, err) + return + } + resp, err := s.SimpleUpload(c, req) + s.Render(c, resp, err) + })...) + router.Handle("POST", "/upload/file/:name/", append(cc.ChainFileUpload(), s.FileUpload)...) + router.Handle("POST", "/upload/image/:name/", s.ImageUpload) router.Handle("POST", "/user/logout/", func(c *gin.Context) { select { case <-c.Request.Context().Done(): @@ -158,9 +183,9 @@ func RegisterSiteServant(e *gin.Engine, s Site, m ...SiteChain) { resp, err := s.PrevTweets(req) s.Render(c, resp, err) } - router.Handle("HEAD", "/tweets/prev/", h) router.Handle("GET", "/tweets/prev/", h) router.Handle("POST", "/tweets/prev/", h) + router.Handle("HEAD", "/tweets/prev/", h) } router.Any("/tweets/next/", func(c *gin.Context) { select { @@ -211,12 +236,12 @@ func (UnimplementedSiteServant) AnyStaticks(c *gin.Context) { c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedSiteServant) Assets(c *gin.Context) { - c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +func (UnimplementedSiteServant) Assets(c *gin.Context, req *LoginReq) mir.Error { + return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } -func (UnimplementedSiteServant) SimpleUpload(c *gin.Context) { - c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +func (UnimplementedSiteServant) SimpleUpload(c *gin.Context, req *LoginReq) (*LoginResp, mir.Error) { + return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } func (UnimplementedSiteServant) FileUpload(c *gin.Context) { diff --git a/examples/mirc/auto/api/v3/site.go b/examples/mirc/auto/api/v3/site.go index b5095ad..5da8f7f 100644 --- a/examples/mirc/auto/api/v3/site.go +++ b/examples/mirc/auto/api/v3/site.go @@ -31,6 +31,7 @@ type Site interface { MultiAttachments(*gin.Context) ManyResources(*gin.Context) AnyStaticks(*gin.Context) + Statics(*gin.Context, *model.LoginReq) mir.Error Assets(*gin.Context) Logout() mir.Error Login(*model.LoginReq) (*model.LoginResp, mir.Error) @@ -61,18 +62,32 @@ func RegisterSiteServant(e *gin.Engine, s Site, m ...SiteChain) { // register routes info to router { h := append(cc.ChainMultiAttachments(), s.MultiAttachments) - router.Handle("OPTIONS", "/attachments", h...) - router.Handle("HEAD", "/attachments", h...) - router.Handle("GET", "/attachments", h...) + router.Handle("OPTIONS", "/attachments/:name/", h...) + router.Handle("HEAD", "/attachments/:name/", h...) + router.Handle("GET", "/attachments/:name/", h...) } { h := s.ManyResources - router.Handle("OPTIONS", "/resources", h) - router.Handle("HEAD", "/resources", h) - router.Handle("GET", "/resources", h) + router.Handle("OPTIONS", "/resources/:name/", h) + router.Handle("HEAD", "/resources/:name/", h) + router.Handle("GET", "/resources/:name/", h) } - router.Any("/staticks", s.AnyStaticks) - router.Handle("GET", "/assets", s.Assets) + router.Any("/anystaticks/:name/", s.AnyStaticks) + router.Handle("GET", "/statics/:name/", func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + req := new(model.LoginReq) + var bv _binding_ = req + if err := bv.Bind(c); err != nil { + s.Render(c, nil, err) + return + } + s.Render(c, nil, s.Statics(c, req)) + }) + router.Handle("GET", "/assets/:name/", s.Assets) router.Handle("POST", "/user/logout/", func(c *gin.Context) { select { case <-c.Request.Context().Done(): @@ -170,6 +185,10 @@ func (UnimplementedSiteServant) AnyStaticks(c *gin.Context) { c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } +func (UnimplementedSiteServant) Statics(c *gin.Context, req *model.LoginReq) mir.Error { + return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +} + func (UnimplementedSiteServant) Assets(c *gin.Context) { c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/examples/mirc/routes/site.go b/examples/mirc/routes/site.go index 9081837..58ee5dc 100644 --- a/examples/mirc/routes/site.go +++ b/examples/mirc/routes/site.go @@ -83,11 +83,12 @@ type Site struct { PrevTweets func(Post, Get, Head, TweetsReq) TweetsResp `mir:"/tweets/prev/"` Login func(Post, LoginReq) LoginResp `mir:"/user/login/"` Logout func(Post, LogoutReq) `mir:"/user/logout/"` - ImageUpload func(Post, Context) `mir:"/upload/image"` - FileUpload func(Post, Chain, Context) `mir:"/upload/file"` - SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple"` - Assets func(Get, Context) `mir:"/assets"` - AnyStaticks func(Any, Context) `mir:"/staticks"` - ManyResources func(Get, Head, Options, Context) `mir:"/resources"` - MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"` + ImageUpload func(Post, Context) `mir:"/upload/image/:name/"` + FileUpload func(Post, Chain, Context) `mir:"/upload/file/:name/"` + SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple/:name/"` + Assets func(Get, Context, LoginReq) `mir:"/assets/:name/"` + Statics func(Get, Context) `mir:"/statics/:name/"` + AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"` + ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"` + MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"` } diff --git a/examples/mirc/routes/v1/site.go b/examples/mirc/routes/v1/site.go index 8f7858e..83eaa5c 100644 --- a/examples/mirc/routes/v1/site.go +++ b/examples/mirc/routes/v1/site.go @@ -21,10 +21,10 @@ type Site struct { AnyTopics func(Chain) `mir:"/topics/"` Articles func(Head, Get, Post, Chain) `mir:"/articles/:category/"` Logout func(Post) `mir:"/user/logout/"` - Assets func(Get, Context) `mir:"/assets"` - AnyStaticks func(Any, Context) `mir:"/staticks"` - ManyResources func(Get, Head, Options, Context) `mir:"/resources"` - MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"` + Assets func(Get, Context) `mir:"/assets/:name/"` + AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"` + ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"` + MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"` } // Admin admin v1 interface info diff --git a/examples/mirc/routes/v2/site.go b/examples/mirc/routes/v2/site.go index 3bfaf0c..c8fa334 100644 --- a/examples/mirc/routes/v2/site.go +++ b/examples/mirc/routes/v2/site.go @@ -61,11 +61,11 @@ type Site struct { PrevTweets func(Post, Get, Head, TweetsReq) TweetsResp `mir:"/tweets/prev/"` Login func(Post, LoginReq) LoginResp `mir:"/user/login/"` Logout func(Post) `mir:"/user/logout/"` - ImageUpload func(Post, Context) `mir:"/upload/image"` - FileUpload func(Post, Chain, Context) `mir:"/upload/file"` - SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple"` - Assets func(Get, Context) `mir:"/assets"` - AnyStaticks func(Any, Context) `mir:"/staticks"` - ManyResources func(Get, Head, Options, Context) `mir:"/resources"` - MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"` + ImageUpload func(Post, Context) `mir:"/upload/image/:name/"` + FileUpload func(Post, Chain, Context) `mir:"/upload/file/:name/"` + SimpleUpload func(Post, Chain, Context, LoginReq) LoginResp `mir:"/upload/simple/:name/"` + Assets func(Get, Context, LoginReq) `mir:"/assets/:name/"` + AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"` + ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"` + MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"` } diff --git a/examples/mirc/routes/v3/site.go b/examples/mirc/routes/v3/site.go index 3f70363..237bdf0 100644 --- a/examples/mirc/routes/v3/site.go +++ b/examples/mirc/routes/v3/site.go @@ -23,8 +23,9 @@ type Site struct { PrevTweets func(Post, Get, Head, model.TweetsReq) model.TweetsResp `mir:"/tweets/prev/"` Login func(Post, model.LoginReq) model.LoginResp `mir:"/user/login/"` Logout func(Post) `mir:"/user/logout/"` - Assets func(Get, Context) `mir:"/assets"` - AnyStaticks func(Any, Context) `mir:"/staticks"` - ManyResources func(Get, Head, Options, Context) `mir:"/resources"` - MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments"` + Assets func(Get, Context) `mir:"/assets/:name/"` + Statics func(Get, Context, model.LoginReq) `mir:"/statics/:name/"` + AnyStaticks func(Any, Context) `mir:"/anystaticks/:name/"` + ManyResources func(Get, Head, Options, Context) `mir:"/resources/:name/"` + MultiAttachments func(Get, Head, Options, Chain, Context) `mir:"/attachments/:name/"` } diff --git a/internal/generator/templates/gin_iface.tmpl b/internal/generator/templates/gin_iface.tmpl index 2e1631a..296cea5 100644 --- a/internal/generator/templates/gin_iface.tmpl +++ b/internal/generator/templates/gin_iface.tmpl @@ -35,7 +35,7 @@ type {{.TypeName}} interface { {{if notEmptyStr .Chain }}// Chain provide handlers chain for gin {{.Chain}}() gin.HandlersChain {{end}} -{{range .Fields}} {{if .IsUseContext}}{{ .MethodName}}(*gin.Context){{else}}{{.MethodName}}({{if notEmptyStr .InName }}*{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} +{{range .Fields}} {{if .JustUseContext }}{{ .MethodName}}(*gin.Context){{else}}{{.MethodName}}({{if .IsUseContext }}*gin.Context{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}*{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} {{end}} mustEmbedUnimplemented{{.TypeName}}Servant() @@ -65,7 +65,7 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField router.Use(middlewares...) {{end}} // register routes info to router -{{range .Fields}}{{if .NotHttpAny }} router.Handle("{{.HttpMethod}}", "{{.Path}}", {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .IsUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { +{{range .Fields}}{{if .NotHttpAny }} router.Handle("{{.HttpMethod}}", "{{.Path}}", {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .JustUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { {{- if $.WatchCtxDone }} select { case <- c.Request.Context().Done(): @@ -86,7 +86,7 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField } {{- end }} {{if notEmptyStr .OutName -}} - resp, err := s.{{ .MethodName}}({{if notEmptyStr .InName}}req{{end}}) + resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}req{{end}}) {{if .IsRenderOut -}} if err != nil { s.Render(c, nil, err) @@ -98,10 +98,10 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField s.Render(c, resp, err) {{- end }} {{- else -}} - s.Render(c, nil, s.{{.MethodName}}({{if notEmptyStr .InName}}req{{end}})) + s.Render(c, nil, s.{{.MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})) {{- end }} }{{end}}{{if .IsFieldChain }})...{{end}}) - {{else if .JustHttpAny}} router.Any("{{.Path}}", {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .IsUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { + {{else if .JustHttpAny}} router.Any("{{.Path}}", {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .JustUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { {{- if $.WatchCtxDone }} select { case <- c.Request.Context().Done(): @@ -122,7 +122,7 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField } {{- end }} {{if notEmptyStr .OutName -}} - resp, err := s.{{ .MethodName}}({{if notEmptyStr .InName}}req{{end}}) + resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}) {{if .IsRenderOut -}} if err != nil { s.Render(c, nil, err) @@ -134,11 +134,11 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField s.Render(c, resp, err) {{- end }} {{- else -}} - s.Render(c, nil, s.{{.MethodName}}({{if notEmptyStr .InName}}req{{end}})) + s.Render(c, nil, s.{{.MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})) {{- end }} }{{end}}{{if .IsFieldChain }})...{{end}}) {{else}}{{$field := .}} { - h := {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .IsUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { + h := {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .JustUseContext}}s.{{ .MethodName}}{{else}}func(c *gin.Context) { {{- if $.WatchCtxDone }} select { case <- c.Request.Context().Done(): @@ -159,7 +159,7 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField } {{- end }} {{if notEmptyStr .OutName -}} - resp, err := s.{{ .MethodName}}({{if notEmptyStr .InName}}req{{end}}) + resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}) {{if .IsRenderOut -}} if err != nil { s.Render(c, nil, err) @@ -171,7 +171,7 @@ func Register{{.TypeName}}Servant(e *gin.Engine, s {{.TypeName}}{{if .IsUseField s.Render(c, resp, err) {{- end }} {{- else -}} - s.Render(c, nil, s.{{.MethodName}}({{if notEmptyStr .InName}}req{{end}})) + s.Render(c, nil, s.{{.MethodName}}({{if .IsUseContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})) {{- end }} }{{end}}{{if .IsFieldChain }}){{end}} {{range .AnyHttpMethods}} router.Handle("{{.}}", "{{$field.Path}}", h{{if $field.IsFieldChain }}...{{end}}) @@ -191,8 +191,8 @@ func ({{$unimplementedServant}}){{.Chain}}() gin.HandlersChain { {{end}} {{range .Fields}} -func ({{$unimplementedServant}}){{if .IsUseContext}}{{ .MethodName}}(c *gin.Context){{else}}{{.MethodName}}({{if notEmptyStr .InName }}req *{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} { - {{if .IsUseContext -}} +func ({{$unimplementedServant}}){{if .JustUseContext}}{{ .MethodName}}(c *gin.Context){{else}}{{.MethodName}}({{if .IsUseContext }}c *gin.Context{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}req *{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} { + {{if .JustUseContext -}} c.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) {{else -}} return {{if notEmptyStr .OutName }}nil, {{end}}mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))