Compare commits

...

3 Commits
v0.0.4 ... main

Author SHA1 Message Date
yanweidong 87734c972f 更新 tpl/logic.go 2025-04-18 12:14:38 +08:00
yanweidong 3b283780ab 更新 tpl/server.go 2025-04-17 23:24:09 +08:00
yanweidong cf7e34c61d 更新 tpl/server.go 2025-04-17 23:16:13 +08:00
2 changed files with 18 additions and 2 deletions

View File

@ -47,6 +47,6 @@ var StatusReplyCode = `
return &pb.StatusReply{
Code: 0,
Message: "OK",
Timeseq: time.Now().UnixNano(),
Timeseq: time.Now().UnixMilli(),
}, nil
`

View File

@ -13,6 +13,7 @@ import (
"git.apinb.com/bsm-sdk/core/vars"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/proto"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)
@ -23,7 +24,9 @@ type Server struct {
}
func New(addr string) *Server {
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux()}
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
)}
// register service to grpc.Server
{register}
@ -58,6 +61,19 @@ func (s *Server) RegisterSwagger() {
})
}
// response envelope
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
name := string(response.ProtoReflect().Descriptor().Name())
if name == "Status" || name == "Error" || name == "StatusReply" {
return response, nil
}
return map[string]any{
"code": 0,
"message": "OK",
"result": response,
}, nil
}
`
var Server = `