Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
5eaac2003d | |||
59922913a9 | |||
d702897cb4 | |||
ec03ee131e | |||
86e3dafc12 | |||
221e4aff6d | |||
d1cc553df8 | |||
454d86cbff |
10
go.mod
10
go.mod
@@ -5,14 +5,14 @@ go 1.19
|
||||
require (
|
||||
github.com/fatih/structtag v1.2.0
|
||||
go.unistack.org/micro-proto/v4 v4.0.1
|
||||
golang.org/x/tools v0.1.12
|
||||
google.golang.org/protobuf v1.28.1
|
||||
golang.org/x/tools v0.11.0
|
||||
google.golang.org/protobuf v1.31.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/gnostic v0.6.9 // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
10
go.sum
10
go.sum
@@ -39,6 +39,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=
|
||||
github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@@ -77,6 +79,8 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -102,6 +106,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@@ -114,6 +120,8 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
|
||||
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -145,6 +153,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
7
http.go
7
http.go
@@ -38,14 +38,15 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
|
||||
}
|
||||
|
||||
for _, service := range file.Services {
|
||||
g.generateServiceEndpoints(gfile, service, component)
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, service)
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
}
|
||||
if genServer {
|
||||
generateServiceServer(gfile, service)
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, service, component)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
main.go
4
main.go
@@ -63,8 +63,8 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
|
||||
g.reflection = *flagReflection
|
||||
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
||||
|
||||
var genClient bool
|
||||
var genServer bool
|
||||
genClient := true
|
||||
genServer := true
|
||||
var genNone bool
|
||||
|
||||
if strings.Contains(g.components, "server") {
|
||||
|
1
micro.go
1
micro.go
@@ -40,7 +40,6 @@ func (g *Generator) microGenerate(component string, plugin *protogen.Plugin, gen
|
||||
// generate services
|
||||
for _, service := range file.Services {
|
||||
g.generateServiceName(gfile, service)
|
||||
g.generateServiceEndpoints(gfile, service)
|
||||
if genClient {
|
||||
g.generateServiceClientInterface(gfile, service)
|
||||
g.generateServiceClientStreamInterface(gfile, service)
|
||||
|
6
rpc.go
6
rpc.go
@@ -37,13 +37,13 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
|
||||
}
|
||||
for _, service := range file.Services {
|
||||
if genClient {
|
||||
g.generateServiceClient(gfile, service)
|
||||
g.generateServiceClient(gfile, file, service)
|
||||
g.generateServiceClientMethods(gfile, service, component)
|
||||
}
|
||||
if genServer {
|
||||
generateServiceServer(gfile, service)
|
||||
g.generateServiceServer(gfile, file, service)
|
||||
g.generateServiceServerMethods(gfile, service)
|
||||
g.generateServiceRegister(gfile, service, component)
|
||||
g.generateServiceRegister(gfile, file, service, component)
|
||||
}
|
||||
if component == "grpc" && g.reflection {
|
||||
g.generateServiceDesc(gfile, file, service)
|
||||
|
27
util.go
27
util.go
@@ -31,7 +31,7 @@ func unexport(s string) string {
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
// if rule, ok := getMicroApiService(service); ok {
|
||||
// gfile.P("// client wrappers ", strings.Join(rule.ClientWrappers, ", "))
|
||||
@@ -41,7 +41,11 @@ func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, service
|
||||
gfile.P("name string")
|
||||
gfile.P("}")
|
||||
|
||||
if g.standalone {
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", file.GoImportPath.Ident(serviceName), "Client {")
|
||||
} else {
|
||||
gfile.P("func New", serviceName, "Client(name string, c ", microClientPackage.Ident("Client"), ") ", serviceName, "Client {")
|
||||
}
|
||||
gfile.P("return &", unexport(serviceName), "Client{c: c, name: name}")
|
||||
gfile.P("}")
|
||||
gfile.P()
|
||||
@@ -319,10 +323,14 @@ func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile,
|
||||
}
|
||||
}
|
||||
|
||||
func generateServiceServer(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
func (g *Generator) generateServiceServer(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
gfile.P("type ", unexport(serviceName), "Server struct {")
|
||||
if g.standalone {
|
||||
gfile.P(file.GoImportPath.Ident(serviceName), "Server")
|
||||
} else {
|
||||
gfile.P(serviceName, "Server")
|
||||
}
|
||||
gfile.P("}")
|
||||
gfile.P()
|
||||
}
|
||||
@@ -477,9 +485,13 @@ func (g *Generator) generateServiceServerMethods(gfile *protogen.GeneratedFile,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, file *protogen.File, service *protogen.Service, component string) {
|
||||
serviceName := service.GoName
|
||||
if g.standalone {
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", file.GoImportPath.Ident(serviceName), "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
} else {
|
||||
gfile.P("func Register", serviceName, "Server(s ", microServerPackage.Ident("Server"), ", sh ", serviceName, "Server, opts ...", microServerPackage.Ident("HandlerOption"), ") error {")
|
||||
}
|
||||
gfile.P("type ", unexport(serviceName), " interface {")
|
||||
for _, method := range service.Methods {
|
||||
generateServerSignature(gfile, serviceName, method, true)
|
||||
@@ -491,7 +503,11 @@ func (g *Generator) generateServiceRegister(gfile *protogen.GeneratedFile, servi
|
||||
gfile.P("h := &", unexport(serviceName), "Server{sh}")
|
||||
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
|
||||
if component == "http" {
|
||||
// if g.standalone {
|
||||
// gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", file.GoImportPath.Ident(serviceName), "ServerEndpoints))")
|
||||
// } else {
|
||||
gfile.P("nopts = append(nopts, ", microServerHttpPackage.Ident("HandlerEndpoints"), "(", serviceName, "ServerEndpoints))")
|
||||
// }
|
||||
}
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
|
||||
gfile.P("}")
|
||||
@@ -839,7 +855,10 @@ func (g *Generator) generateServiceName(gfile *protogen.GeneratedFile, service *
|
||||
gfile.P(")")
|
||||
}
|
||||
|
||||
func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
func (g *Generator) generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
|
||||
if component != "http" {
|
||||
return
|
||||
}
|
||||
serviceName := service.GoName
|
||||
|
||||
gfile.P("var (")
|
||||
|
@@ -16,10 +16,10 @@ var (
|
||||
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v4/server")
|
||||
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v4")
|
||||
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v4")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro/v4/codec")
|
||||
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v4/codec")
|
||||
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v4/errors")
|
||||
grpcPackage = protogen.GoImportPath("google.golang.org/grpc")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v4.0.1"
|
||||
versionComment = "v4.0.2"
|
||||
)
|
||||
|
Reference in New Issue
Block a user