Skip to content

Commit

Permalink
feat(templates): update api frame template
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Nov 27, 2024
1 parent b5920cd commit b4923d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .template/frame/api/app/desc/api/version.api.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ type GetResponse {
group: version
)
service {{ .APP | ToCamel }} {
@handler GetHandler
@handler Get
get /version (GetRequest) returns (GetResponse)
}
6 changes: 6 additions & 0 deletions .template/frame/api/app/internal/middleware/middleware.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
)

type Middleware struct {}

func NewMiddleware() Middleware {
return Middleware{}
}

func Register(server *rest.Server) {
httpx.SetOkHandler(ResponseMiddleware)
httpx.SetErrorHandler(ErrorMiddleware)
Expand Down
6 changes: 5 additions & 1 deletion .template/frame/api/app/internal/svc/service_context.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package svc
import (
"{{ .Module }}/internal/config"
"{{ .Module }}/internal/custom"
"{{ .Module }}/internal/middleware"
)

type ServiceContext struct {
Config config.Config
Custom *custom.Custom
// middleware
middleware.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
Custom: custom.New(),
Middleware: middleware.NewMiddleware(),
}
}

0 comments on commit b4923d7

Please sign in to comment.