feat(transport): added ability to enable gRPC reflection

This commit is contained in:
ITQ
2025-10-27 22:35:53 +03:00
parent db44030c9f
commit 21935804f9
4 changed files with 20 additions and 4 deletions
+10 -2
View File
@@ -9,8 +9,9 @@ import (
)
type Config struct {
GRPCPort int
LogLevel string
GRPCPort int
GRPCEnableReflection bool
LogLevel string
}
func Load() (*Config, error) {
@@ -27,6 +28,13 @@ func Load() (*Config, error) {
}
config.GRPCPort = port
enableReflectionStr := getEnv("GRPC_ENABLE_REFLECTION", "false")
enableReflection, err := strconv.ParseBool(enableReflectionStr)
if err != nil {
return nil, err
}
config.GRPCEnableReflection = enableReflection
config.LogLevel = getEnv("LOG_LEVEL", "info")
return config, nil
+6
View File
@@ -12,6 +12,7 @@ import (
pb "orderservice/pkg/api/order"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
type Server struct {
@@ -36,6 +37,11 @@ func New(cfg *config.Config) *Server {
func (s *Server) RegisterServices() {
orderService := service.NewOrderServiceServer()
pb.RegisterOrderServiceServer(s.grpcServer, orderService)
if s.config.GRPCEnableReflection {
reflection.Register(s.grpcServer)
log.Println("gRPC server will start with reflection")
}
}
func (s *Server) Start() error {