Skip to content

Commit

Permalink
Add option to configure unbound HTTP method warnings (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
yousseftelda authored Aug 22, 2020
1 parent 5adc227 commit 969062a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/descriptor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ type Registry struct {
simpleOperationIDs bool

standalone 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 +527,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 internal/descriptor/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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).")
standalone = flag.Bool("standalone", false, "generates a standalone gateway package, which imports the target service package")
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.SetImportPath(*importPath)
reg.SetAllowDeleteBody(*allowDeleteBody)
reg.SetAllowRepeatedFieldsInBody(*allowRepeatedFieldsInBody)
reg.SetWarnOnUnboundMethods(*warnOnUnboundMethods)
if err := reg.SetRepeatedPathParamSeparator(*repeatedPathParamSeparator); err != nil {
emitError(err)
return
Expand Down

0 comments on commit 969062a

Please sign in to comment.