Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #1606 against v2 #1609

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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