Skip to content

Commit

Permalink
Control warning behavior on unbound methods using a flag (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
yousseftelda committed Aug 21, 2020
1 parent 5a43216 commit d44c040
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions protoc-gen-grpc-gateway/descriptor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type Registry struct {
// simpleOperationIDs removes the service prefix from the generated
// operationIDs. This risks generating duplicate operationIDs.
simpleOperationIDs bool

// warnOnUnboundMethods causes the registry to emit warning logs if an RPC method
// has no HttpRule annotation.
warnOnUnboundMethods bool
}

type repeatedFieldSeparator struct {
Expand Down Expand Up @@ -524,6 +528,11 @@ func (r *Registry) GetSimpleOperationIDs() bool {
return r.simpleOperationIDs
}

// SetWarnOnUnboundMethods sets warnOnUnboundMethods
func (r *Registry) SetWarnOnUnboundMethods(warn bool) {
r.warnOnUnboundMethods = warn
}

// sanitizePackageName replaces unallowed character in package name
// with allowed character.
func sanitizePackageName(pkgName string) string {
Expand Down
6 changes: 5 additions & 1 deletion protoc-gen-grpc-gateway/descriptor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (r *Registry) loadServices(file *File) error {
optsList = append(optsList, opts)
}
if len(optsList) == 0 {
glog.Warningf("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName())
logFn := glog.V(1).Infof
if r.warnOnUnboundMethods {
logFn = glog.Warningf
}
logFn("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName())
}
meth, err := r.newMethod(svc, md, optsList)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions protoc-gen-grpc-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
allowPatchFeature = flag.Bool("allow_patch_feature", true, "determines whether to use PATCH feature involving update masks (using google.protobuf.FieldMask).")
allowColonFinalSegments = flag.Bool("allow_colon_final_segments", false, "determines whether colons are permitted in the final segment of a path")
versionFlag = flag.Bool("version", false, "print the current version")
warnOnUnboundMethods = flag.Bool("warn_on_unbound_methods", false, "emit a warning message if an RPC method has no HttpRule annotation")
)

// Variables set by goreleaser at build time
Expand Down Expand Up @@ -96,6 +97,7 @@ func main() {
reg.SetAllowDeleteBody(*allowDeleteBody)
reg.SetAllowRepeatedFieldsInBody(*allowRepeatedFieldsInBody)
reg.SetAllowColonFinalSegments(*allowColonFinalSegments)
reg.SetWarnOnUnboundMethods(*warnOnUnboundMethods)
if err := reg.SetRepeatedPathParamSeparator(*repeatedPathParamSeparator); err != nil {
emitError(err)
return
Expand Down

0 comments on commit d44c040

Please sign in to comment.