add grpc server support

This commit is contained in:
yanghao05
2023-05-06 15:29:16 +08:00
parent 3a9a1a6eeb
commit 4964b59b2c
9 changed files with 156 additions and 35 deletions

23
services/grpc.go Normal file
View File

@@ -0,0 +1,23 @@
package services
import (
"github.com/rogeecn/atom/container"
"github.com/rogeecn/atom/providers/grpcs"
"go.uber.org/dig"
)
type GrpcService struct {
dig.In
Server *grpcs.Grpc
Services []grpcs.ServerService `group:"grpc_server_services"`
}
func ServeGrpc() error {
return container.Container.Invoke(func(grpc GrpcService) error {
for _, svc := range grpc.Services {
grpc.Server.RegisterService(svc.Name(), svc.Register)
}
return grpc.Server.Serve()
})
}