本文整理匯總了Golang中github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/descriptor.Registry類的典型用法代碼示例。如果您正苦於以下問題:Golang Registry類的具體用法?Golang Registry怎麽用?Golang Registry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Registry類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: New
// New returns a new generator which generates grpc gateway files.
func New(reg *descriptor.Registry) gen.Generator {
var imports []descriptor.GoPackage
for _, pkgpath := range []string{
"encoding/json",
"io",
"net/http",
"github.com/gengo/grpc-gateway/runtime",
"github.com/gengo/grpc-gateway/utilities",
"github.com/golang/glog",
"github.com/golang/protobuf/proto",
"golang.org/x/net/context",
"google.golang.org/grpc",
"google.golang.org/grpc/codes",
} {
pkg := descriptor.GoPackage{
Path: pkgpath,
Name: path.Base(pkgpath),
}
if err := reg.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil {
for i := 0; ; i++ {
alias := fmt.Sprintf("%s_%d", pkg.Name, i)
if err := reg.ReserveGoPackageAlias(alias, pkg.Path); err != nil {
continue
}
pkg.Alias = alias
break
}
}
imports = append(imports, pkg)
}
return &generator{reg: reg, baseImports: imports}
}
示例2: findNestedMessages
// findNestedMessages that can be generated by the services.
func findNestedMessages(message *descriptor.Message, reg *descriptor.Registry, m messageMap) {
// Iterate over all the fields that
for _, t := range message.Fields {
fieldType := t.GetTypeName()
// If the type is an empty string then it is a proto primitive
if fieldType != "" {
if _, ok := m[fieldType]; !ok {
msg, err := reg.LookupMsg("", fieldType)
if err != nil {
panic(err)
}
m[fieldType] = msg
findNestedMessages(msg, reg, m)
}
}
}
}
示例3: fullyQualifiedNameToSwaggerName
// Take in a FQMN and return a swagger safe version of the FQMN
func fullyQualifiedNameToSwaggerName(fqmn string, reg *descriptor.Registry) string {
return resolveFullyQualifiedNameToSwaggerName(fqmn, reg.GetAllFQMNs())
}
示例4: fullyQualifiedNameToSwaggerName
// Take in a FQMN or FQEN and return a swagger safe version of the FQMN
func fullyQualifiedNameToSwaggerName(fqn string, reg *descriptor.Registry) string {
return resolveFullyQualifiedNameToSwaggerName(fqn, append(reg.GetAllFQMNs(), reg.GetAllFQENs()...))
}