New returns a new generator which generates grpc gateway files.
(reg *descriptor.Registry, useRequestContext bool, registerFuncSuffix string, allowPatchFeature, standalone bool, useOpaqueAPI bool)
| 27 | |
| 28 | // New returns a new generator which generates grpc gateway files. |
| 29 | func New(reg *descriptor.Registry, useRequestContext bool, registerFuncSuffix string, |
| 30 | allowPatchFeature, standalone bool, useOpaqueAPI bool) gen.Generator { |
| 31 | var imports []descriptor.GoPackage |
| 32 | for _, pkgpath := range []string{ |
| 33 | "context", |
| 34 | "errors", |
| 35 | "io", |
| 36 | "net/http", |
| 37 | "github.com/grpc-ecosystem/grpc-gateway/v2/runtime", |
| 38 | "github.com/grpc-ecosystem/grpc-gateway/v2/utilities", |
| 39 | "google.golang.org/protobuf/proto", |
| 40 | "google.golang.org/grpc", |
| 41 | "google.golang.org/grpc/codes", |
| 42 | "google.golang.org/grpc/grpclog", |
| 43 | "google.golang.org/grpc/metadata", |
| 44 | "google.golang.org/grpc/status", |
| 45 | } { |
| 46 | pkg := descriptor.GoPackage{ |
| 47 | Path: pkgpath, |
| 48 | Name: path.Base(pkgpath), |
| 49 | } |
| 50 | if err := reg.ReserveGoPackageAlias(pkg.Name, pkg.Path); err != nil { |
| 51 | for i := 0; ; i++ { |
| 52 | alias := fmt.Sprintf("%s_%d", pkg.Name, i) |
| 53 | if err := reg.ReserveGoPackageAlias(alias, pkg.Path); err != nil { |
| 54 | continue |
| 55 | } |
| 56 | pkg.Alias = alias |
| 57 | break |
| 58 | } |
| 59 | } |
| 60 | imports = append(imports, pkg) |
| 61 | } |
| 62 | |
| 63 | return &generator{ |
| 64 | reg: reg, |
| 65 | baseImports: imports, |
| 66 | useRequestContext: useRequestContext, |
| 67 | registerFuncSuffix: registerFuncSuffix, |
| 68 | allowPatchFeature: allowPatchFeature, |
| 69 | standalone: standalone, |
| 70 | useOpaqueAPI: useOpaqueAPI, |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.ResponseFile, error) { |
| 75 | var files []*descriptor.ResponseFile |
no test coverage detected