Skip to content

Commit

Permalink
support custom server options when constructing handlers
Browse files Browse the repository at this point in the history
useful when implemention your own `main.go`
  • Loading branch information
zaquestion committed Nov 27, 2019
1 parent 2ace737 commit d4a9ae6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion gengokit/httptransport/templates/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ var (
// MakeHTTPHandler returns a handler that makes a set of endpoints available
// on predefined paths.
func MakeHTTPHandler(endpoints Endpoints) http.Handler {
func MakeHTTPHandler(endpoints Endpoints, options ...httptransport.ServerOption) http.Handler {
{{- if .HTTPHelper.Methods}}
serverOptions := []httptransport.ServerOption{
httptransport.ServerBefore(headersToContext),
httptransport.ServerErrorEncoder(errorEncoder),
httptransport.ServerAfter(httptransport.SetContentType(contentType)),
}
serverOptions = append(serverOptions, options...)
{{- end }}
m := mux.NewRouter()
Expand Down
5 changes: 3 additions & 2 deletions gengokit/template/NAME-service/svc/transport_grpc.gotemplate
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
)

// MakeGRPCServer makes a set of endpoints available as a gRPC {{.Service.Name}}Server.
func MakeGRPCServer(endpoints Endpoints) pb.{{.Service.Name}}Server {
func MakeGRPCServer(endpoints Endpoints, options ...grpctransport.ServerOption) pb.{{.Service.Name}}Server {
serverOptions := []grpctransport.ServerOption{
grpctransport.ServerBefore(metadataToContext),
grpctransport.ServerBefore(metadataToContext),
}
serverOptions = append(serverOptions, options...)
return &grpcServer{
// {{ ToLower .Service.Name }}
{{range $i := .Service.Methods}}
Expand Down
8 changes: 4 additions & 4 deletions gengokit/template/template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4a9ae6

Please sign in to comment.