Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee4d83458f | |||
dd62c380f2 | |||
e4f2867419 | |||
c5f68efd4c | |||
140c5fb90a | |||
b4231422b3 |
37
ast.go
37
ast.go
@@ -15,20 +15,9 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
astFields = make(map[string]map[string]map[string]*structtag.Tags) // map proto file with proto message ast struct
|
||||
)
|
||||
var astFields = make(map[string]map[string]map[string]*structtag.Tags) // map proto file with proto message ast struct
|
||||
|
||||
func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
if g.tagPath == "" {
|
||||
return nil
|
||||
}
|
||||
for _, file := range plugin.Files {
|
||||
if !file.Generate {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, message := range file.Messages {
|
||||
func (g *Generator) astFill(file *protogen.File, message *protogen.Message) error {
|
||||
for _, field := range message.Fields {
|
||||
if field.Desc.Options() == nil {
|
||||
continue
|
||||
@@ -57,6 +46,28 @@ func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
astFields[fpath] = mp
|
||||
}
|
||||
}
|
||||
for _, nmessage := range message.Messages {
|
||||
if err := g.astFill(file, nmessage); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Generator) astGenerate(plugin *protogen.Plugin) error {
|
||||
if g.tagPath == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, file := range plugin.Files {
|
||||
if !file.Generate {
|
||||
continue
|
||||
}
|
||||
for _, message := range file.Messages {
|
||||
if err := g.astFill(file, message); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
6
go.mod
6
go.mod
@@ -4,9 +4,7 @@ go 1.16
|
||||
|
||||
require (
|
||||
github.com/fatih/structtag v1.2.0
|
||||
github.com/unistack-org/micro-proto v0.0.2
|
||||
github.com/unistack-org/micro-proto v0.0.8
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.26.0
|
||||
google.golang.org/protobuf v1.27.1
|
||||
)
|
||||
|
||||
//replace github.com/unistack-org/micro-proto => ../micro-proto
|
||||
|
8
go.sum
8
go.sum
@@ -26,8 +26,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/unistack-org/micro-proto v0.0.2 h1:mL1ZPRGPCWJOiMBiJrkk8Y513rPrJmhJWxyLceckAXU=
|
||||
github.com/unistack-org/micro-proto v0.0.2/go.mod h1:GYO53DWmeldRIo90cAdQx8bLr/WJMxW62W4ja74p1Ac=
|
||||
github.com/unistack-org/micro-proto v0.0.8 h1:g4UZGQGeYGI3CFJtjuEm47aouYPviG8SDhSifl0831w=
|
||||
github.com/unistack-org/micro-proto v0.0.8/go.mod h1:GYO53DWmeldRIo90cAdQx8bLr/WJMxW62W4ja74p1Ac=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -69,7 +69,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
14
util.go
14
util.go
@@ -55,14 +55,14 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
||||
opts := proto.GetExtension(method.Desc.Options(), openapiv2_options.E_Openapiv2Operation)
|
||||
if opts != nil {
|
||||
r := opts.(*openapiv2_options.Operation)
|
||||
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses), ")")
|
||||
for code, response := range r.Responses {
|
||||
if response.Schema != nil && response.Schema.JsonSchema != nil {
|
||||
ref := response.Schema.JsonSchema.Ref
|
||||
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseCode), ")")
|
||||
for _, rsp := range r.Responses.ResponseCode {
|
||||
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
||||
ref := schema.XRef
|
||||
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
|
||||
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
|
||||
}
|
||||
gfile.P(`errmap["`, code, `"] = &`, ref, "{}")
|
||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,6 +449,8 @@ func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service
|
||||
func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "Name", "=", `"`, serviceName, `"`)
|
||||
gfile.P()
|
||||
gfile.P(serviceName, "Endpoints", "=", "[]", microApiPackage.Ident("Endpoint"), "{")
|
||||
for _, method := range service.Methods {
|
||||
if method.Desc.Options() == nil {
|
||||
@@ -457,7 +459,7 @@ func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.S
|
||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
endpoints, streaming := generateEndpoints(method)
|
||||
for _, endpoint := range endpoints {
|
||||
gfile.P(microApiPackage.Ident("Endpoint"), "{")
|
||||
gfile.P("{")
|
||||
generateEndpoint(gfile, serviceName, method.GoName, endpoint, streaming)
|
||||
gfile.P("},")
|
||||
}
|
||||
|
@@ -17,5 +17,5 @@ var (
|
||||
microClientHttpPackage = protogen.GoImportPath("github.com/unistack-org/micro-client-http/v3")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v3.4.1"
|
||||
versionComment = "v3.4.2"
|
||||
)
|
||||
|
Reference in New Issue
Block a user