Esempio n. 1
0
// 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}
}
Esempio n. 2
0
// 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)
			}
		}
	}
}
Esempio n. 3
0
// 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())
}
Esempio n. 4
0
// 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()...))
}