Skip to content

Commit

Permalink
Merge pull request #200 from wubin1989/main
Browse files Browse the repository at this point in the history
optimize code gen
  • Loading branch information
wubin1989 authored May 5, 2024
2 parents 208178f + 2f18177 commit 24e1972
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/internal/svc/codegen/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Parameter struct {
Sort string
Order string
Fields string
Filters []interface{}
Filters string
}
func (receiver Parameter) GetPage() int64 {
Expand Down
11 changes: 7 additions & 4 deletions cmd/internal/templates/mainmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ func main() {
)),
)
lis, dialCtx := pipeconn.NewPipeListener()
for _, v := range plugin.GetServicePlugins() {
v.Initialize(srv, grpcServer, dialCtx)
plugins := plugin.GetServicePlugins()
for _, key := range plugins.Keys() {
value, _ := plugins.Get(key)
value.Initialize(srv, grpcServer, dialCtx)
}
defer func() {
if r := recover(); r != nil {
zlogger.Info().Msgf("Recovered. Error: %v\n", r)
}
for _, v := range plugin.GetServicePlugins() {
v.Close()
for _, key := range plugins.Keys() {
value, _ := plugins.Get(key)
value.Close()
}
}()
go func() {
Expand Down
11 changes: 7 additions & 4 deletions cmd/internal/templates/mainmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import (
func main() {
srv := rest.NewRestServer()
grpcServer := grpcx.NewEmptyGrpcServer()
for _, v := range plugin.GetServicePlugins() {
v.Initialize(srv, grpcServer, nil)
plugins := plugin.GetServicePlugins()
for _, key := range plugins.Keys() {
value, _ := plugins.Get(key)
value.Initialize(srv, grpcServer, nil)
}
defer func() {
if r := recover(); r != nil {
zlogger.Info().Msgf("Recovered. Error: %v\n", r)
}
for _, v := range plugin.GetServicePlugins() {
v.Close()
for _, key := range plugins.Keys() {
value, _ := plugins.Get(key)
value.Close()
}
}()
go func() {
Expand Down
6 changes: 6 additions & 0 deletions cmd/internal/templates/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var _ plugin.ServicePlugin = (*{{.SvcName}}Plugin)(nil)
type {{.SvcName}}Plugin struct {
grpcConns []*grpc.ClientConn
serviceInstance service.{{.SvcName}}
}
func (receiver *{{.SvcName}}Plugin) GetServiceInstance() interface{} {
return receiver.serviceInstance
}
func (receiver *{{.SvcName}}Plugin) Close() {
Expand All @@ -52,6 +57,7 @@ func (receiver *{{.SvcName}}Plugin) GetName() string {
func (receiver *{{.SvcName}}Plugin) Initialize(restServer *rest.RestServer, grpcServer *grpcx.GrpcServer, dialCtx pipeconn.DialContextFunc) {
conf := config.LoadFromEnv()
svc := {{.ServiceAlias}}.New{{.SvcName}}(conf)
receiver.serviceInstance = svc
restServer.AddRoute(httpsrv.Routes(httpsrv.New{{.SvcName}}Handler(svc))...)
if grpcServer.Server == nil {
grpcServer.Server = grpc.NewServer(
Expand Down

0 comments on commit 24e1972

Please sign in to comment.