Skip to content

Commit

Permalink
feat: 更新模板生成的处理程序和发送器类型,调整相关接口定义
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Feb 13, 2025
1 parent e25f8bf commit eab288a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
21 changes: 14 additions & 7 deletions contrib/protoc-gen-route/template.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{{$extraDataType := .ExtraDataType}}
{{$newExtraDataFunc := .NewExtraDataFunc}}

{{$handlerType := printf "func(ctx context.Context, request *%s) error" $requestType}}
{{$senderType := printf "func(ctx context.Context, request *%s, msg *%s) error" $requestType $responseType}}

{{- range .MethodSets}}
const Operation{{$optionsKey}}{{$svrType}}{{.OriginalName}} = "/{{$svrName}}/{{.OriginalName}}"
{{- end}}
Expand Down Expand Up @@ -35,6 +38,14 @@ func GetExtra{{$optionsKey}}DataBy{{$svrType}}Operation(operation string) *{{.Ex
}
}

func GetAll{{$optionsKey}}{{$svrType}}Operations() []string {
return []string{
{{- range .MethodSets}}
Operation{{$optionsKey}}{{$svrType}}{{.OriginalName}},
{{- end}}
}
}

type {{.ServiceType}}{{$optionsKey}}Server interface {
{{- range .MethodSets}}
{{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error)
Expand All @@ -48,12 +59,8 @@ type {{.ServiceType}}{{$optionsKey}}Codec interface {
{{- end}}
}

type {{.ServiceType}}{{$optionsKey}}Handler func(ctx context.Context, request *{{.RequestType}}) error

type {{.ServiceType}}{{$optionsKey}}Sender func(ctx context.Context, request *{{.RequestType}}, msg *{{.ResponseType}}) error

{{range .Methods}}
func _{{$svrType}}_{{.Name}}{{.Num}}_{{$optionsKey}}_Handler(srv {{$svrType}}{{$optionsKey}}Server, codec {{$svrType}}{{$optionsKey}}Codec, sender {{$svrType}}{{$optionsKey}}Sender) {{$svrType}}{{$optionsKey}}Handler {
func _{{$svrType}}_{{.Name}}{{.Num}}_{{$optionsKey}}_Handler(srv {{$svrType}}{{$optionsKey}}Server, codec {{$svrType}}{{$optionsKey}}Codec, sender {{$senderType}}) {{$handlerType}} {
return func(ctx context.Context, request *{{$requestType}}) error {
req, err := codec.Decode{{.Name}}Request(ctx, request)
if err != nil {
Expand All @@ -72,8 +79,8 @@ func _{{$svrType}}_{{.Name}}{{.Num}}_{{$optionsKey}}_Handler(srv {{$svrType}}{{$
}
{{end}}

func Register{{.ServiceType}}{{$optionsKey}}Server(srv {{.ServiceType}}{{$optionsKey}}Server, codec {{.ServiceType}}{{$optionsKey}}Codec, sender {{.ServiceType}}{{$optionsKey}}Sender) map[string]{{.ServiceType}}{{$optionsKey}}Handler {
handlers := make(map[string]{{.ServiceType}}{{$optionsKey}}Handler)
func Register{{.ServiceType}}{{$optionsKey}}Server(srv {{.ServiceType}}{{$optionsKey}}Server, codec {{.ServiceType}}{{$optionsKey}}Codec, sender {{$senderType}}) map[string]{{$handlerType}} {
handlers := make(map[string]{{$handlerType}})
{{- range .Methods}}
handlers[Operation{{$optionsKey}}{{$svrType}}{{.OriginalName}}] = _{{$svrType}}_{{.Name}}{{.Num}}_{{$optionsKey}}_Handler(srv, codec, sender)
{{- end}}
Expand Down
10 changes: 5 additions & 5 deletions layout/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ fabric.properties

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go

/swagger
/build
/var
/api
/config.json
swagger
build
var
api
config.json
2 changes: 1 addition & 1 deletion layout/internal/pkg/database/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/ent
ent

0 comments on commit eab288a

Please sign in to comment.