Skip to content

Commit

Permalink
# feat(pb): 新增Unimplemented结构体,实现接口时只要内嵌该结构体即可,不需要实现所有的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
guihouchang committed Mar 14, 2023
1 parent 4bd60f4 commit c04ddac
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type {{.ServiceType}}EventServer interface {
{{- range .MethodSets}}
{{.Name}}(context.Context, *{{.Request}}) error
{{- end}}
mustEmbedUnimplemented{{.ServiceType}}EventServer()
}
func Register{{.ServiceType}}EventServer(r *message.Router, sg func(topic string) message.Subscriber, srv {{.ServiceType}}EventServer) {
Expand Down Expand Up @@ -73,6 +74,7 @@ func (c *{{$svrType}}EventClientImpl) {{.Name}}(ctx context.Context, req *{{.Req
return c.publisher.Publish(topic, msg)
}
{{end}}
{{range .MethodSets}}
{{if gt .EventDelay 0}}
func (c *{{$svrType}}EventClientImpl) {{.Name}}WithDelay(ctx context.Context, req *{{.Request}}, delay uint64) error {
Expand All @@ -89,6 +91,18 @@ func (c *{{$svrType}}EventClientImpl) {{.Name}}WithDelay(ctx context.Context, re
}
{{end}}
{{end}}
type Unsafe{{.ServiceType}}EventServer interface {
mustEmbedUnimplemented{{.ServiceType}}EventServer()
}
type Unimplemented{{.ServiceType}}EventServer struct {}
{{- range .MethodSets}}
func (Unimplemented{{$svrType}}EventServer) {{.Name}}(context.Context, *{{.Request}}) error {
return nil
}
{{- end}}
`

type serviceDesc struct {
Expand Down

0 comments on commit c04ddac

Please sign in to comment.