From 3f1ab9931c5dc7dc1b02e95d80acd08f4c1b3069 Mon Sep 17 00:00:00 2001 From: barry Date: Thu, 20 Jun 2024 22:34:33 +0800 Subject: [PATCH 01/41] fix: 2024-06-20 22:34:33 --- go.mod | 1 + go.sum | 6 + pkg/gateway/code.go | 2 + pkg/gateway/internal/routertree/parser.go | 182 ++++++++++++++++++++++ pkg/gateway/internal/routertree/router.go | 129 +++++++++++++++ pkg/gateway/mux.go | 23 ++- pkg/gateway/stream_proxy.go | 44 ++++++ pkg/gateway/util.go | 50 ++++++ 8 files changed, 431 insertions(+), 6 deletions(-) create mode 100644 pkg/gateway/internal/routertree/parser.go create mode 100644 pkg/gateway/internal/routertree/router.go create mode 100644 pkg/gateway/stream_proxy.go diff --git a/go.mod b/go.mod index c449b84b..43ff7a21 100644 --- a/go.mod +++ b/go.mod @@ -41,6 +41,7 @@ require ( require ( entgo.io/ent v0.13.1 github.com/DATA-DOG/go-sqlmock v1.5.2 + github.com/alecthomas/participle/v2 v2.1.1 github.com/arl/statsviz v0.6.0 github.com/dave/jennifer v1.7.0 github.com/deckarep/golang-set/v2 v2.6.0 diff --git a/go.sum b/go.sum index 59c00822..eef6781a 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,10 @@ github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tj github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/ahmetb/go-linq v3.0.0+incompatible h1:qQkjjOXKrKOTy83X8OpRmnKflXKQIL/mC/gMVVDMhOA= github.com/ahmetb/go-linq v3.0.0+incompatible/go.mod h1:PFffvbdbtw+QTB0WKRP0cNht7vnCfnGlEpak/DVg5cY= +github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= +github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= +github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6icjJvbsmV8= +github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -236,6 +240,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= diff --git a/pkg/gateway/code.go b/pkg/gateway/code.go index d33f1327..0d256fda 100644 --- a/pkg/gateway/code.go +++ b/pkg/gateway/code.go @@ -7,6 +7,8 @@ import ( "google.golang.org/grpc/codes" ) +// https://github.com/dapr/kit/tree/main/grpccodes + var codeToHTTPStatus = [...]int{ http.StatusOK, // 0 http.StatusRequestTimeout, // 1 diff --git a/pkg/gateway/internal/routertree/parser.go b/pkg/gateway/internal/routertree/parser.go new file mode 100644 index 00000000..c2bae817 --- /dev/null +++ b/pkg/gateway/internal/routertree/parser.go @@ -0,0 +1,182 @@ +package routertree + +import ( + "strings" + + "github.com/alecthomas/participle/v2" + "github.com/alecthomas/participle/v2/lexer" + "github.com/pubgo/funk/assert" + "github.com/pubgo/funk/errors" + "github.com/pubgo/funk/generic" +) + +const ( + doubleStar = "**" + star = "*" +) + +var ( + parser = assert.Exit1(participle.Build[httpRule]( + participle.Lexer(assert.Exit1(lexer.NewSimple([]lexer.SimpleRule{ + {Name: "Ident", Pattern: `[a-zA-Z]\w*`}, + {Name: "Punct", Pattern: `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`}, + }))), + )) +) + +// httpRule +// Template = "/" Segments [ Verb ] ; +// Segments = Segment { "/" Segment } ; +// Segment = "*" | "**" | LITERAL | Variable ; +// Variable = "{" FieldPath [ "=" Segments ] "}" ; +// FieldPath = IDENT { "." IDENT } ; +// Verb = ":" LITERAL ; +type httpRule struct { + Slash string `@"/"` + Segments *segments `@@!` + Verb *string `(":" @Ident)?` +} + +type segments struct { + Segments []*segment `@@ ("/" @@)*` +} + +type segment struct { + Path *string `@("*" "*" | "*" | Ident)` + Variable *variable `| @@` +} + +type variable struct { + Fields []string `"{" @Ident ("." @Ident)*` + Segments *segments `("=" @@)? "}"` +} + +type pathVariable struct { + Fields []string + start, end int +} + +type routePath struct { + Paths []string + Verb *string + Vars []*pathVariable +} + +type pathFieldVar struct { + Fields []string + Value string +} + +func (r routePath) Match(urls []string, verb string) ([]pathFieldVar, error) { + if len(urls) < len(r.Paths) { + return nil, errors.New("urls length not match") + } + + if r.Verb != nil { + if generic.FromPtr(r.Verb) != verb { + return nil, errors.New("verb not match") + } + } + + for i := range r.Paths { + path := r.Paths[i] + if path == star { + continue + } + + if path == urls[i] { + continue + } + + if path == doubleStar { + continue + } + + return nil, errors.New("path is not match") + } + + var vv []pathFieldVar + for _, v := range r.Vars { + pathVar := pathFieldVar{Fields: v.Fields} + if v.end > 0 { + pathVar.Value = strings.Join(urls[v.start:v.end+1], "/") + } else { + pathVar.Value = strings.Join(urls[v.start:], "/") + } + + vv = append(vv, pathVar) + } + + return vv, nil +} + +func (r routePath) String() string { + url := "/" + + paths := make([]string, len(r.Paths)) + copy(paths, r.Paths) + + for _, v := range r.Vars { + varS := "{" + strings.Join(v.Fields, ".") + "=" + end := generic.Ternary(v.end == -1, len(paths)-1, v.end) + + for i := v.start; i <= end; i++ { + varS += generic.Ternary(i == v.start, paths[i], "/"+paths[i]) + if i > v.start { + paths[i] = "" + } + } + + varS += "}" + paths[v.start] = varS + } + + url += strings.Join(generic.Filter(paths, func(s string) bool { return s != "" }), "/") + + if r.Verb != nil { + url += ":" + generic.FromPtr(r.Verb) + } + + return url +} + +func handleSegments(s *segment, rr *routePath) { + if s.Path != nil { + rr.Paths = append(rr.Paths, *s.Path) + return + } + + vv := &pathVariable{Fields: s.Variable.Fields, start: len(rr.Paths)} + if s.Variable.Segments == nil { + rr.Paths = append(rr.Paths, star) + } else { + for _, v := range s.Variable.Segments.Segments { + handleSegments(v, rr) + } + } + + if len(rr.Paths) > 0 && rr.Paths[len(rr.Paths)-1] == doubleStar { + vv.end = -1 + } else { + vv.end = len(rr.Paths) - 1 + } + + rr.Vars = append(rr.Vars, vv) +} + +func parseToRoute(rule *httpRule) *routePath { + r := new(routePath) + r.Verb = rule.Verb + + if rule.Segments != nil { + for _, v := range rule.Segments.Segments { + handleSegments(v, r) + } + } + + return r +} + +func parse(url string) (*httpRule, error) { + return parser.ParseString("", url) +} diff --git a/pkg/gateway/internal/routertree/router.go b/pkg/gateway/internal/routertree/router.go new file mode 100644 index 00000000..39ac10e6 --- /dev/null +++ b/pkg/gateway/internal/routertree/router.go @@ -0,0 +1,129 @@ +package routertree + +import ( + "fmt" + "strings" + + "github.com/pubgo/funk/errors" + "github.com/pubgo/funk/generic" +) + +var ( + ErrPathNodeNotFound = errors.New("path node not found") + ErrNotFound = errors.New("operation not found") +) + +func NewRouteTree() *RouteTree { + return &RouteTree{nodes: make(map[string]*pathNode)} +} + +type RouteTree struct { + nodes map[string]*pathNode +} + +func (r *RouteTree) Add(method string, url string, operation string) error { + rule, err := parse(url) + if err != nil { + return err + } + + var node = parseToRoute(rule) + if len(node.Paths) == 0 { + return fmt.Errorf("path is null") + } + + var nodes = r.nodes + for i, n := range node.Paths { + var lastNode = nodes[n] + if lastNode == nil { + lastNode = &pathNode{ + nodes: make(map[string]*pathNode), + verbs: make(map[string]*routeTarget), + } + nodes[n] = lastNode + } + nodes = lastNode.nodes + + if i == len(node.Paths)-1 { + lastNode.verbs[generic.FromPtr(node.Verb)] = &routeTarget{ + Method: method, + Operation: &operation, + Verb: &method, + Vars: node.Vars, + } + } + } + return nil +} + +func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { + var paths = strings.Split(strings.Trim(strings.TrimSpace(url), "/"), "/") + var lastPath = strings.SplitN(paths[len(paths)-1], ":", 2) + var verb = "" + + paths[len(paths)-1] = lastPath[0] + if len(lastPath) > 1 { + verb = lastPath[1] + } + + var getVars = func(vars []*pathVariable, paths []string) []pathFieldVar { + var vv = make([]pathFieldVar, 0, len(vars)) + for _, v := range vars { + pathVar := pathFieldVar{Fields: v.Fields} + if v.end > 0 { + pathVar.Value = strings.Join(paths[v.start:v.end+1], "/") + } else { + pathVar.Value = strings.Join(paths[v.start:], "/") + } + + vv = append(vv, pathVar) + } + return vv + } + var getPath = func(nodes map[string]*pathNode, names ...string) *pathNode { + for _, n := range names { + path := nodes[n] + if path != nil { + return path + } + } + return nil + } + + var nodes = r.nodes + for _, n := range paths { + path := getPath(nodes, n, star, doubleStar) + if path == nil { + return nil, errors.Wrapf(ErrPathNodeNotFound, "node=%s", n) + } + + if vv := path.verbs[verb]; vv != nil && vv.Operation != nil && vv.Method == method { + return &MatchOperation{ + Operation: generic.FromPtr(vv.Operation), + Verb: verb, + Vars: getVars(vv.Vars, paths), + }, nil + } + nodes = path.nodes + } + + return nil, errors.Wrapf(ErrNotFound, "method=%s path=%s", method, url) +} + +type routeTarget struct { + Method string + Operation *string + Verb *string + Vars []*pathVariable +} + +type pathNode struct { + nodes map[string]*pathNode + verbs map[string]*routeTarget +} + +type MatchOperation struct { + Operation string + Verb string + Vars []pathFieldVar +} diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 0c45a2db..88a953d8 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -19,6 +19,7 @@ import ( "github.com/pubgo/funk/log" "github.com/pubgo/funk/version" "github.com/pubgo/lava/lava" + "github.com/pubgo/lava/pkg/gateway/internal/routertree" "github.com/pubgo/lava/pkg/gateway/internal/routex" "github.com/pubgo/lava/pkg/httputil" "google.golang.org/grpc" @@ -124,9 +125,10 @@ func CompressorOption(contentEncoding string, c Compressor) MuxOption { var _ Gateway = (*Mux)(nil) type Mux struct { - cc *inprocgrpc.Channel - opts *muxOptions - route *routex.RouteTrie + cc *inprocgrpc.Channel + opts *muxOptions + route *routex.RouteTrie + routerTree *routertree.RouteTree } func (m *Mux) GetRouteMethods() []*routex.RouteTarget { @@ -238,9 +240,10 @@ func NewMux(opts ...MuxOption) *Mux { sort.Strings(muxOpts.encodingTypeOffers) mux := &Mux{ - opts: &muxOpts, - cc: new(inprocgrpc.Channel), - route: routex.NewRouteTrie(), + opts: &muxOpts, + cc: new(inprocgrpc.Channel), + route: routex.NewRouteTrie(), + routerTree: routertree.NewRouteTree(), } return mux @@ -316,7 +319,12 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcMethod: methodDesc, grpcMethodName: grpcMethod, }) + assert.Must(m.route.AddRoute(grpcMethod, methodDesc)) + assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { + return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) + })) + } for i := range gsd.Streams { @@ -333,6 +341,9 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcMethodName: grpcMethod, }) assert.Must(m.route.AddRoute(grpcMethod, methodDesc)) + assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { + return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) + })) } return nil diff --git a/pkg/gateway/stream_proxy.go b/pkg/gateway/stream_proxy.go new file mode 100644 index 00000000..2860c3ce --- /dev/null +++ b/pkg/gateway/stream_proxy.go @@ -0,0 +1,44 @@ +package gateway + +import ( + "context" + + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var _ grpc.ServerStream = (*serverProxyStream)(nil) + +type serverProxyStream struct { + cli grpc.ClientStream +} + +func (s serverProxyStream) SetHeader(md metadata.MD) error { + //TODO implement me + panic("implement me") +} + +func (s serverProxyStream) SendHeader(md metadata.MD) error { + //TODO implement me + panic("implement me") +} + +func (s serverProxyStream) SetTrailer(md metadata.MD) { + //TODO implement me + panic("implement me") +} + +func (s serverProxyStream) Context() context.Context { + //TODO implement me + panic("implement me") +} + +func (s serverProxyStream) SendMsg(m any) error { + //TODO implement me + panic("implement me") +} + +func (s serverProxyStream) RecvMsg(m any) error { + //TODO implement me + panic("implement me") +} diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index 0fe07916..f5697786 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -3,6 +3,8 @@ package gateway import ( "context" "encoding/base64" + "fmt" + "github.com/pubgo/funk/errors" "net/http" "net/textproto" "strconv" @@ -139,3 +141,51 @@ func newIncomingContext(ctx context.Context, header http.Header) (context.Contex } return metadata.NewIncomingContext(ctx, md), md } + +func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path string) error) error { + if httpRule == nil { + return nil + } + + var method, template string + switch pattern := httpRule.GetPattern().(type) { + case *annotations.HttpRule_Get: + method, template = http.MethodGet, pattern.Get + case *annotations.HttpRule_Put: + method, template = http.MethodPut, pattern.Put + case *annotations.HttpRule_Post: + method, template = http.MethodPost, pattern.Post + case *annotations.HttpRule_Delete: + method, template = http.MethodDelete, pattern.Delete + case *annotations.HttpRule_Patch: + method, template = http.MethodPatch, pattern.Patch + case *annotations.HttpRule_Custom: + method, template = pattern.Custom.GetKind(), pattern.Custom.GetPath() + default: + return fmt.Errorf("invalid type of pattern for HTTP httpRule: %T", pattern) + } + + if method == "" { + return errors.New("invalid HTTP httpRule: HttpMethod is blank") + } + + if template == "" { + return errors.New("invalid HTTP httpRule: HttpPath template is blank") + } + + if err := cb(method, template); err != nil { + return err + } + + for i, rule := range httpRule.GetAdditionalBindings() { + if len(rule.GetAdditionalBindings()) > 0 { + return fmt.Errorf("nested additional bindings are not supported") + } + + if err := handlerHttpRoute(rule, cb); err != nil { + return fmt.Errorf("failed to add REST route (add'l binding #%d): %w", i+1, err) + } + } + + return nil +} From a5af67ef53c751dc85bae96bf17624feda900b7b Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 21 Jun 2024 11:59:51 +0800 Subject: [PATCH 02/41] fix: 2024-06-21 11:59:51 --- pkg/gateway/httprule.go | 49 ----------------------------------------- pkg/gateway/wrapper.go | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 pkg/gateway/httprule.go create mode 100644 pkg/gateway/wrapper.go diff --git a/pkg/gateway/httprule.go b/pkg/gateway/httprule.go deleted file mode 100644 index 18cc619c..00000000 --- a/pkg/gateway/httprule.go +++ /dev/null @@ -1,49 +0,0 @@ -package gateway - -import ( - "github.com/pubgo/funk/errors" - "google.golang.org/grpc" - "google.golang.org/protobuf/reflect/protoreflect" -) - -type serviceWrap struct { - opts *muxOptions - srv interface{} - serviceDesc *grpc.ServiceDesc - servicePB protoreflect.ServiceDescriptor -} - -type methodWrap struct { - srv *serviceWrap - methodDesc *grpc.MethodDesc - streamDesc *grpc.StreamDesc - grpcMethod protoreflect.MethodDescriptor - - // /{ServiceName}/{MethodName} - grpcMethodName string -} - -func (h methodWrap) Handle(stream grpc.ServerStream) error { - if h.methodDesc != nil { - ctx := stream.Context() - - reply, err := h.methodDesc.Handler(h.srv.srv, ctx, stream.RecvMsg, h.srv.opts.unaryInterceptor) - if err != nil { - return errors.WrapCaller(err) - } - - return errors.WrapCaller(stream.SendMsg(reply)) - } else { - info := &grpc.StreamServerInfo{ - FullMethod: h.grpcMethodName, - IsClientStream: h.streamDesc.ClientStreams, - IsServerStream: h.streamDesc.ServerStreams, - } - - if h.srv.opts.streamInterceptor != nil { - return h.srv.opts.streamInterceptor(h.srv.srv, stream, info, h.streamDesc.Handler) - } else { - return h.streamDesc.Handler(h.srv.srv, stream) - } - } -} diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go new file mode 100644 index 00000000..f223b076 --- /dev/null +++ b/pkg/gateway/wrapper.go @@ -0,0 +1,49 @@ +package gateway + +import ( + "github.com/pubgo/funk/errors" + "google.golang.org/grpc" + "google.golang.org/protobuf/reflect/protoreflect" +) + +type serviceWrapper struct { + opts *muxOptions + srv interface{} + serviceDesc *grpc.ServiceDesc + servicePbDesc protoreflect.ServiceDescriptor +} + +type methodWrapper struct { + srv *serviceWrapper + grpcMethodDesc *grpc.MethodDesc + grpcStreamDesc *grpc.StreamDesc + grpcMethodPbDesc protoreflect.MethodDescriptor + + // /{ServiceName}/{MethodName} + grpcFullMethod string +} + +func (h methodWrapper) Handle(stream grpc.ServerStream) error { + if h.grpcMethodDesc != nil { + ctx := stream.Context() + + reply, err := h.grpcMethodDesc.Handler(h.srv.srv, ctx, stream.RecvMsg, h.srv.opts.unaryInterceptor) + if err != nil { + return errors.WrapCaller(err) + } + + return errors.WrapCaller(stream.SendMsg(reply)) + } else { + info := &grpc.StreamServerInfo{ + FullMethod: h.grpcFullMethod, + IsClientStream: h.grpcStreamDesc.ClientStreams, + IsServerStream: h.grpcStreamDesc.ServerStreams, + } + + if h.srv.opts.streamInterceptor != nil { + return errors.WrapCaller(h.srv.opts.streamInterceptor(h.srv.srv, stream, info, h.grpcStreamDesc.Handler)) + } else { + return errors.WrapCaller(h.grpcStreamDesc.Handler(h.srv.srv, stream)) + } + } +} From 9658fd2850d101ca8ead8c6f655d961c637c1053 Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 21 Jun 2024 12:00:02 +0800 Subject: [PATCH 03/41] fix: 2024-06-21 12:00:02 --- pkg/gateway/aaa.go | 10 +-- pkg/gateway/internal/routertree/parser.go | 8 +-- pkg/gateway/internal/routertree/router.go | 78 +++++++++++++++++------ pkg/gateway/mux.go | 76 ++++++++++------------ pkg/gateway/stream_http.go | 16 ++--- pkg/gateway/util.go | 19 ++---- 6 files changed, 119 insertions(+), 88 deletions(-) diff --git a/pkg/gateway/aaa.go b/pkg/gateway/aaa.go index 3617a3a2..493b3e13 100644 --- a/pkg/gateway/aaa.go +++ b/pkg/gateway/aaa.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/gofiber/fiber/v2" - "github.com/pubgo/lava/pkg/gateway/internal/routex" + "github.com/pubgo/lava/pkg/gateway/internal/routertree" "google.golang.org/grpc" "google.golang.org/grpc/encoding" "google.golang.org/protobuf/proto" @@ -13,8 +13,10 @@ import ( ) type ( - RouteTarget = routex.RouteTarget - Gateway interface { + MatchOperation = routertree.MatchOperation + PathFieldVar = routertree.PathFieldVar + RouteOperation = routertree.RouteOperation + Gateway interface { grpc.ClientConnInterface SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor) @@ -25,7 +27,7 @@ type ( Handler(*fiber.Ctx) error ServeHTTP(http.ResponseWriter, *http.Request) - GetRouteMethods() []*routex.RouteTarget + GetRouteMethods() []RouteOperation } ) diff --git a/pkg/gateway/internal/routertree/parser.go b/pkg/gateway/internal/routertree/parser.go index c2bae817..bd383f99 100644 --- a/pkg/gateway/internal/routertree/parser.go +++ b/pkg/gateway/internal/routertree/parser.go @@ -62,12 +62,12 @@ type routePath struct { Vars []*pathVariable } -type pathFieldVar struct { +type PathFieldVar struct { Fields []string Value string } -func (r routePath) Match(urls []string, verb string) ([]pathFieldVar, error) { +func (r routePath) Match(urls []string, verb string) ([]PathFieldVar, error) { if len(urls) < len(r.Paths) { return nil, errors.New("urls length not match") } @@ -95,9 +95,9 @@ func (r routePath) Match(urls []string, verb string) ([]pathFieldVar, error) { return nil, errors.New("path is not match") } - var vv []pathFieldVar + var vv []PathFieldVar for _, v := range r.Vars { - pathVar := pathFieldVar{Fields: v.Fields} + pathVar := PathFieldVar{Fields: v.Fields} if v.end > 0 { pathVar.Value = strings.Join(urls[v.start:v.end+1], "/") } else { diff --git a/pkg/gateway/internal/routertree/router.go b/pkg/gateway/internal/routertree/router.go index 39ac10e6..8dba5495 100644 --- a/pkg/gateway/internal/routertree/router.go +++ b/pkg/gateway/internal/routertree/router.go @@ -14,30 +14,38 @@ var ( ) func NewRouteTree() *RouteTree { - return &RouteTree{nodes: make(map[string]*pathNode)} + return &RouteTree{nodes: make(map[string]*nodeTree)} } type RouteTree struct { - nodes map[string]*pathNode + nodes map[string]*nodeTree +} + +func (r *RouteTree) List() []RouteOperation { + return getOpt(r.nodes) } func (r *RouteTree) Add(method string, url string, operation string) error { + var errMsg = func() string { + return fmt.Sprintf("method: %s, url: %s, operation: %s", method, url, operation) + } + rule, err := parse(url) if err != nil { - return err + return errors.Wrap(err, errMsg()) } var node = parseToRoute(rule) if len(node.Paths) == 0 { - return fmt.Errorf("path is null") + return errors.Wrap(fmt.Errorf("path is null"), errMsg()) } var nodes = r.nodes for i, n := range node.Paths { var lastNode = nodes[n] if lastNode == nil { - lastNode = &pathNode{ - nodes: make(map[string]*pathNode), + lastNode = &nodeTree{ + nodes: make(map[string]*nodeTree), verbs: make(map[string]*routeTarget), } nodes[n] = lastNode @@ -47,7 +55,8 @@ func (r *RouteTree) Add(method string, url string, operation string) error { if i == len(node.Paths)-1 { lastNode.verbs[generic.FromPtr(node.Verb)] = &routeTarget{ Method: method, - Operation: &operation, + Path: url, + Operation: operation, Verb: &method, Vars: node.Vars, } @@ -59,6 +68,9 @@ func (r *RouteTree) Add(method string, url string, operation string) error { func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { var paths = strings.Split(strings.Trim(strings.TrimSpace(url), "/"), "/") var lastPath = strings.SplitN(paths[len(paths)-1], ":", 2) + var errMsg = func(tags ...errors.Tag) errors.Tags { + return append(tags, errors.T("method", method), errors.T("url", url)) + } var verb = "" paths[len(paths)-1] = lastPath[0] @@ -66,10 +78,10 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { verb = lastPath[1] } - var getVars = func(vars []*pathVariable, paths []string) []pathFieldVar { - var vv = make([]pathFieldVar, 0, len(vars)) + var getVars = func(vars []*pathVariable, paths []string) []PathFieldVar { + var vv = make([]PathFieldVar, 0, len(vars)) for _, v := range vars { - pathVar := pathFieldVar{Fields: v.Fields} + pathVar := PathFieldVar{Fields: v.Fields} if v.end > 0 { pathVar.Value = strings.Join(paths[v.start:v.end+1], "/") } else { @@ -80,7 +92,7 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { } return vv } - var getPath = func(nodes map[string]*pathNode, names ...string) *pathNode { + var getPath = func(nodes map[string]*nodeTree, names ...string) *nodeTree { for _, n := range names { path := nodes[n] if path != nil { @@ -94,12 +106,14 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { for _, n := range paths { path := getPath(nodes, n, star, doubleStar) if path == nil { - return nil, errors.Wrapf(ErrPathNodeNotFound, "node=%s", n) + return nil, errors.WrapFn(ErrPathNodeNotFound, func() errors.Tags { + return errMsg(errors.T("node", n)) + }) } - if vv := path.verbs[verb]; vv != nil && vv.Operation != nil && vv.Method == method { + if vv := path.verbs[verb]; vv != nil && vv.Operation != "" && vv.Method == method { return &MatchOperation{ - Operation: generic.FromPtr(vv.Operation), + Operation: vv.Operation, Verb: verb, Vars: getVars(vv.Vars, paths), }, nil @@ -107,23 +121,49 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { nodes = path.nodes } - return nil, errors.Wrapf(ErrNotFound, "method=%s path=%s", method, url) + return nil, errors.WrapTag(ErrNotFound, errMsg()...) +} + +type RouteOperation struct { + Method string `json:"method,omitempty"` + Path string `json:"path,omitempty"` + Operation string `json:"operation,omitempty"` + Verb string `json:"verb,omitempty"` + Vars []string `json:"vars,omitempty"` } type routeTarget struct { Method string - Operation *string + Path string + Operation string Verb *string Vars []*pathVariable } -type pathNode struct { - nodes map[string]*pathNode +type nodeTree struct { + nodes map[string]*nodeTree verbs map[string]*routeTarget } type MatchOperation struct { Operation string Verb string - Vars []pathFieldVar + Vars []PathFieldVar +} + +func getOpt(nodes map[string]*nodeTree) []RouteOperation { + var sets []RouteOperation + for _, n := range nodes { + for _, v := range n.verbs { + sets = append(sets, RouteOperation{ + Method: v.Method, + Path: v.Path, + Operation: v.Operation, + Verb: generic.FromPtr(v.Verb), + Vars: generic.Map(v.Vars, func(i int) string { return strings.Join(v.Vars[i].Fields, ".") }), + }) + } + sets = append(sets, getOpt(n.nodes)...) + } + return sets } diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 88a953d8..3562bade 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -8,6 +8,7 @@ import ( "net/url" "reflect" "sort" + "strings" "time" "github.com/fullstorydev/grpchan/inprocgrpc" @@ -20,7 +21,6 @@ import ( "github.com/pubgo/funk/version" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/gateway/internal/routertree" - "github.com/pubgo/lava/pkg/gateway/internal/routex" "github.com/pubgo/lava/pkg/httputil" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -45,7 +45,7 @@ type muxOptions struct { errHandler func(err error, ctx *fiber.Ctx) requestInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error responseInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error - handlers map[string]*methodWrap + handlers map[string]*methodWrapper } // MuxOption is an option for a mux. @@ -66,7 +66,7 @@ var ( types: protoregistry.GlobalTypes, responseInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), requestInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), - handlers: make(map[string]*methodWrap), + handlers: make(map[string]*methodWrapper), } defaultCodecs = map[string]Codec{ @@ -127,13 +127,10 @@ var _ Gateway = (*Mux)(nil) type Mux struct { cc *inprocgrpc.Channel opts *muxOptions - route *routex.RouteTrie routerTree *routertree.RouteTree } -func (m *Mux) GetRouteMethods() []*routex.RouteTarget { - return m.route.GetRouteMethods() -} +func (m *Mux) GetRouteMethods() []RouteOperation { return m.routerTree.List() } func (m *Mux) SetResponseEncoder(name protoreflect.FullName, f func(ctx *fiber.Ctx, msg proto.Message) error) { m.opts.responseInterceptors[name] = f @@ -144,29 +141,29 @@ func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ct } func (m *Mux) Handler(ctx *fiber.Ctx) error { - restTarget, restVars, _ := m.route.Match(string(ctx.Request().URI().Path()), ctx.Method()) - if restTarget == nil { - return errors.Wrapf(fiber.ErrNotFound, "path=%s", string(ctx.Request().URI().Path())) + matchOperation, err := m.routerTree.Match(ctx.Method(), string(ctx.Request().URI().Path())) + if err != nil { + return errors.WrapCaller(err) } defer func() { ctx.Response().Header.Set(httputil.HeaderXRequestID, lava.GetReqID(ctx.Context())) ctx.Response().Header.Set(httputil.HeaderXRequestVersion, version.Version()) - ctx.Response().Header.Set(httputil.HeaderXRequestOperation, restTarget.GrpcMethodName) + ctx.Response().Header.Set(httputil.HeaderXRequestOperation, matchOperation.Operation) }() values := make(url.Values) - for _, v := range restVars { - values.Set(v.Name, v.Value) + for _, v := range matchOperation.Vars { + values.Set(strings.Join(v.Fields, "."), v.Value) } for k, v := range ctx.Queries() { values.Set(k, v) } - mth := m.opts.handlers[restTarget.GrpcMethodName] + mth := m.opts.handlers[matchOperation.Operation] if mth == nil { - return errors.NewFmt("grpc method not found, method=%s", restTarget.GrpcMethodName) + return errors.Format("grpc method not found, method=%s", matchOperation.Operation) } md := metadata.New(nil) @@ -180,7 +177,7 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { ctx: rspCtx, method: mth, params: values, - path: restTarget, + path: matchOperation, })) } @@ -242,7 +239,6 @@ func NewMux(opts ...MuxOption) *Mux { mux := &Mux{ opts: &muxOpts, cc: new(inprocgrpc.Channel), - route: routex.NewRouteTrie(), routerTree: routertree.NewRouteTree(), } @@ -278,8 +274,8 @@ func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { } } -func (m *Mux) registerRouter(rule *methodWrap) { - m.opts.handlers[rule.grpcMethodName] = rule +func (m *Mux) registerRouter(rule *methodWrapper) { + m.opts.handlers[rule.grpcFullMethod] = rule } func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { @@ -293,11 +289,11 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { return errors.Format("invalid httpPathRule descriptor %T", d) } - srv := &serviceWrap{ - opts: m.opts, - srv: ss, - serviceDesc: gsd, - servicePB: sd, + srv := &serviceWrapper{ + opts: m.opts, + srv: ss, + serviceDesc: gsd, + servicePbDesc: sd, } findMethodDesc := func(methodName string) protoreflect.MethodDescriptor { @@ -313,18 +309,16 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcMethod := fmt.Sprintf("/%s/%s", gsd.ServiceName, grpcMth.MethodName) assert.If(m.opts.handlers[grpcMethod] != nil, "grpc httpPathRule has existed") - m.registerRouter(&methodWrap{ - srv: srv, - methodDesc: grpcMth, - grpcMethod: methodDesc, - grpcMethodName: grpcMethod, + m.registerRouter(&methodWrapper{ + srv: srv, + grpcMethodDesc: grpcMth, + grpcMethodPbDesc: methodDesc, + grpcFullMethod: grpcMethod, }) - assert.Must(m.route.AddRoute(grpcMethod, methodDesc)) assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) })) - } for i := range gsd.Streams { @@ -334,13 +328,13 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { methodDesc := findMethodDesc(grpcMth.StreamName) - m.registerRouter(&methodWrap{ - srv: srv, - streamDesc: grpcMth, - grpcMethod: methodDesc, - grpcMethodName: grpcMethod, + m.registerRouter(&methodWrapper{ + srv: srv, + grpcStreamDesc: grpcMth, + grpcMethodPbDesc: methodDesc, + grpcFullMethod: grpcMethod, }) - assert.Must(m.route.AddRoute(grpcMethod, methodDesc)) + assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) })) @@ -349,7 +343,7 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { return nil } -func GetRouterTarget(mux *Mux, kind, path string) (*RouteTarget, error) { +func GetRouterTarget(mux *Mux, kind, path string) (*MatchOperation, error) { if path == "" { return nil, errors.New("path is null") } @@ -358,9 +352,9 @@ func GetRouterTarget(mux *Mux, kind, path string) (*RouteTarget, error) { kind = "ws" } - restTarget, _, _ := mux.route.Match(path, kind) - if restTarget == nil { - return nil, errors.Format("path not found, kind=%s path=%s", kind, path) + restTarget, err := mux.routerTree.Match(path, kind) + if err != nil { + return nil, errors.Wrapf(err, "path not found, kind=%s path=%s", kind, path) } return restTarget, nil diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index 452043d2..3316a851 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -9,7 +9,7 @@ import ( "github.com/gofiber/fiber/v2" "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" "github.com/pubgo/funk/errors" - "github.com/pubgo/lava/pkg/gateway/internal/routex" + "github.com/pubgo/lava/pkg/gateway/internal/routertree" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/encoding/protojson" @@ -17,8 +17,8 @@ import ( ) type streamHTTP struct { - method *methodWrap - path *routex.RouteTarget + method *methodWrapper + path *routertree.MatchOperation handler *fiber.Ctx ctx context.Context header metadata.MD @@ -61,7 +61,7 @@ func (s *streamHTTP) Context() context.Context { s.ctx, &serverTransportStream{ ServerStream: s, - method: s.method.grpcMethodName, + method: s.method.grpcFullMethod, }, ) } @@ -98,10 +98,10 @@ func (s *streamHTTP) SendMsg(m interface{}) error { func (s *streamHTTP) RecvMsg(m interface{}) error { args := m.(proto.Message) - if s.path.HttpMethod == http.MethodPut || - s.path.HttpMethod == http.MethodPost || - s.path.HttpMethod == http.MethodDelete || - s.path.HttpMethod == http.MethodPatch { + if s.handler.Method() == http.MethodPut || + s.handler.Method() == http.MethodPost || + s.handler.Method() == http.MethodDelete || + s.handler.Method() == http.MethodPatch { cur := args.ProtoReflect() for _, fd := range s.path.RequestBodyFields { cur = cur.Mutable(fd).Message() diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index f5697786..c07a8ea6 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -3,13 +3,12 @@ package gateway import ( "context" "encoding/base64" - "fmt" - "github.com/pubgo/funk/errors" "net/http" "net/textproto" "strconv" "strings" + "github.com/pubgo/funk/errors" "google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" @@ -50,11 +49,7 @@ func quote(raw []byte) []byte { // getExtensionHTTP func getExtensionHTTP(m protoreflect.MethodDescriptor) *annotations.HttpRule { - if m == nil { - return nil - } - - if m.Options() == nil { + if m == nil || m.Options() == nil { return nil } @@ -142,7 +137,7 @@ func newIncomingContext(ctx context.Context, header http.Header) (context.Contex return metadata.NewIncomingContext(ctx, md), md } -func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path string) error) error { +func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path string, reqBody, rspBody string) error) error { if httpRule == nil { return nil } @@ -162,7 +157,7 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s case *annotations.HttpRule_Custom: method, template = pattern.Custom.GetKind(), pattern.Custom.GetPath() default: - return fmt.Errorf("invalid type of pattern for HTTP httpRule: %T", pattern) + return errors.Format("invalid type of pattern for HTTP httpRule: %T", pattern) } if method == "" { @@ -173,17 +168,17 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s return errors.New("invalid HTTP httpRule: HttpPath template is blank") } - if err := cb(method, template); err != nil { + if err := cb(method, template, httpRule.GetBody(), httpRule.GetResponseBody()); err != nil { return err } for i, rule := range httpRule.GetAdditionalBindings() { if len(rule.GetAdditionalBindings()) > 0 { - return fmt.Errorf("nested additional bindings are not supported") + return errors.New("nested additional bindings are not supported") } if err := handlerHttpRoute(rule, cb); err != nil { - return fmt.Errorf("failed to add REST route (add'l binding #%d): %w", i+1, err) + return errors.Format("failed to add REST route (add'l binding #%d): %w", i+1, err) } } From 343aeb917c00dc037da50f909c67b20eba3939c5 Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 21 Jun 2024 14:23:34 +0800 Subject: [PATCH 04/41] fix: 2024-06-21 14:23:34 --- pkg/gateway/internal/routertree/router.go | 35 ++++++----- pkg/gateway/mux.go | 8 +-- pkg/gateway/stream_http.go | 4 +- pkg/gateway/util.go | 72 ++++++++++++++++++++++- 4 files changed, 98 insertions(+), 21 deletions(-) diff --git a/pkg/gateway/internal/routertree/router.go b/pkg/gateway/internal/routertree/router.go index 8dba5495..aaa692fb 100644 --- a/pkg/gateway/internal/routertree/router.go +++ b/pkg/gateway/internal/routertree/router.go @@ -25,12 +25,12 @@ func (r *RouteTree) List() []RouteOperation { return getOpt(r.nodes) } -func (r *RouteTree) Add(method string, url string, operation string) error { +func (r *RouteTree) Add(method string, path string, operation string, extras map[string]any) error { var errMsg = func() string { - return fmt.Sprintf("method: %s, url: %s, operation: %s", method, url, operation) + return fmt.Sprintf("method: %s, path: %s, operation: %s", method, path, operation) } - rule, err := parse(url) + rule, err := parse(path) if err != nil { return errors.Wrap(err, errMsg()) } @@ -44,10 +44,7 @@ func (r *RouteTree) Add(method string, url string, operation string) error { for i, n := range node.Paths { var lastNode = nodes[n] if lastNode == nil { - lastNode = &nodeTree{ - nodes: make(map[string]*nodeTree), - verbs: make(map[string]*routeTarget), - } + lastNode = &nodeTree{nodes: make(map[string]*nodeTree), verbs: make(map[string]*routeTarget)} nodes[n] = lastNode } nodes = lastNode.nodes @@ -55,9 +52,10 @@ func (r *RouteTree) Add(method string, url string, operation string) error { if i == len(node.Paths)-1 { lastNode.verbs[generic.FromPtr(node.Verb)] = &routeTarget{ Method: method, - Path: url, + Path: path, Operation: operation, - Verb: &method, + extras: extras, + Verb: node.Verb, Vars: node.Vars, } } @@ -113,6 +111,9 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { if vv := path.verbs[verb]; vv != nil && vv.Operation != "" && vv.Method == method { return &MatchOperation{ + Extras: vv.extras, + Method: vv.Method, + Path: vv.Path, Operation: vv.Operation, Verb: verb, Vars: getVars(vv.Vars, paths), @@ -125,11 +126,12 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { } type RouteOperation struct { - Method string `json:"method,omitempty"` - Path string `json:"path,omitempty"` - Operation string `json:"operation,omitempty"` - Verb string `json:"verb,omitempty"` - Vars []string `json:"vars,omitempty"` + Method string `json:"method,omitempty"` + Path string `json:"path,omitempty"` + Operation string `json:"operation,omitempty"` + Verb string `json:"verb,omitempty"` + Vars []string `json:"vars,omitempty"` + Extras map[string]any `json:"extras"` } type routeTarget struct { @@ -138,6 +140,7 @@ type routeTarget struct { Operation string Verb *string Vars []*pathVariable + extras map[string]any } type nodeTree struct { @@ -146,9 +149,12 @@ type nodeTree struct { } type MatchOperation struct { + Method string + Path string Operation string Verb string Vars []PathFieldVar + Extras map[string]any } func getOpt(nodes map[string]*nodeTree) []RouteOperation { @@ -161,6 +167,7 @@ func getOpt(nodes map[string]*nodeTree) []RouteOperation { Operation: v.Operation, Verb: generic.FromPtr(v.Verb), Vars: generic.Map(v.Vars, func(i int) string { return strings.Join(v.Vars[i].Fields, ".") }), + Extras: v.extras, }) } sets = append(sets, getOpt(n.nodes)...) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 3562bade..366901e1 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -316,8 +316,8 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcFullMethod: grpcMethod, }) - assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { - return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) + assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { + return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod, resolveBodyDesc(methodDesc, reqBody, rspBody))) })) } @@ -335,8 +335,8 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcFullMethod: grpcMethod, }) - assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string) error { - return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod)) + assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { + return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod, resolveBodyDesc(methodDesc, reqBody, rspBody))) })) } diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index 3316a851..c6af1b14 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -75,7 +75,7 @@ func (s *streamHTTP) SendMsg(m interface{}) error { } cur := reply.ProtoReflect() - for _, fd := range s.path.ResponseBodyFields { + for _, fd := range getReqBodyDesc(s.path) { cur = cur.Mutable(fd).Message() } msg := cur.Interface() @@ -103,7 +103,7 @@ func (s *streamHTTP) RecvMsg(m interface{}) error { s.handler.Method() == http.MethodDelete || s.handler.Method() == http.MethodPatch { cur := args.ProtoReflect() - for _, fd := range s.path.RequestBodyFields { + for _, fd := range getRspBodyDesc(s.path) { cur = cur.Mutable(fd).Message() } msg := cur.Interface() diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index c07a8ea6..e313fb96 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -3,18 +3,38 @@ package gateway import ( "context" "encoding/base64" + "fmt" "net/http" "net/textproto" "strconv" "strings" + "github.com/pubgo/funk/assert" "github.com/pubgo/funk/errors" + "github.com/pubgo/lava/pkg/gateway/internal/routertree" "google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" ) +func getReqBodyDesc(path *routertree.MatchOperation) []protoreflect.FieldDescriptor { + return path.Extras["req_body_desc"].([]protoreflect.FieldDescriptor) +} + +func getRspBodyDesc(path *routertree.MatchOperation) []protoreflect.FieldDescriptor { + return path.Extras["rsp_body_desc"].([]protoreflect.FieldDescriptor) +} + +func resolveBodyDesc(methodDesc protoreflect.MethodDescriptor, reqBody, rspBody string) map[string]any { + return map[string]any{ + "req_body_field": reqBody, + "req_body_desc": assert.Must1(resolvePathToDescriptors(methodDesc.Input(), reqBody)), + "rsp_body_field": rspBody, + "rsp_body_desc": assert.Must1(resolvePathToDescriptors(methodDesc.Output(), rspBody)), + } +} + func fieldPathToDesc(fields protoreflect.FieldDescriptors, names ...string) []protoreflect.FieldDescriptor { fds := make([]protoreflect.FieldDescriptor, len(names)) for i, name := range names { @@ -168,7 +188,19 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s return errors.New("invalid HTTP httpRule: HttpPath template is blank") } - if err := cb(method, template, httpRule.GetBody(), httpRule.GetResponseBody()); err != nil { + var reqBody = httpRule.GetBody() + switch reqBody { + case "", "*": + reqBody = "*" + } + + var rspBody = httpRule.GetResponseBody() + switch rspBody { + case "", "*": + rspBody = "*" + } + + if err := cb(method, template, reqBody, rspBody); err != nil { return err } @@ -184,3 +216,41 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s return nil } + +func resolvePathToDescriptors(msg protoreflect.MessageDescriptor, path string) ([]protoreflect.FieldDescriptor, error) { + if path == "" { + return nil, nil + } + if path == "*" { + // non-nil, empty slice means use the whole thing + return []protoreflect.FieldDescriptor{}, nil + } + + fields := msg.Fields() + parts := strings.Split(path, ".") + result := make([]protoreflect.FieldDescriptor, len(parts)) + for i, part := range parts { + field := fields.ByName(protoreflect.Name(part)) + if field == nil { + return nil, errors.Format("in field HttpPath %q: element %q does not correspond to any field of type %s", + path, part, msg.FullName()) + } + + result[i] = field + if i == len(parts)-1 { + break + } + + if field.Cardinality() == protoreflect.Repeated { + return nil, errors.Format("in field HttpPath %q: field %q of type %s should not be a list or map", path, part, msg.FullName()) + } + + msg = field.Message() + if msg == nil { + return nil, fmt.Errorf("in field HttpPath %q: field %q of type %s should be a message", path, part, field.Kind()) + } + + fields = msg.Fields() + } + return result, nil +} From 0e8754096140de8339c400e76086f0e81793aff5 Mon Sep 17 00:00:00 2001 From: barry Date: Fri, 21 Jun 2024 22:38:28 +0800 Subject: [PATCH 05/41] fix: 2024-06-21 22:38:28 --- servers/grpcs/server.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index 93491a0e..c700b241 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -370,14 +370,13 @@ func (s *serviceImpl) DixInject( httpServer.Group(apiPrefix1, httputil.StripPrefix(apiPrefix1, mux.Handler)) for _, m := range mux.GetRouteMethods() { log.Info(). - Str("method-name", m.GrpcMethodName). - Str("http-method", m.HttpMethod). - Str("http-path", apiPrefix1+"/"+strings.Join(m.HttpPath, "/")). + Str("method-name", m.Operation). + Str("http-method", m.Method). + Str("http-path", assert.Must1(url.JoinPath(apiPrefix1, m.Path))). Str("verb", m.Verb). - Str("req-field-path", m.RequestBodyFieldPath). - Str("rsp-field-path", m.ResponseBodyFieldPath). Any("path-vars", m.Vars). - Msg("grpc gateway method router") + Any("extras", m.Extras). + Msg("grpc gateway router info") } apiPrefix := assert.Must1(url.JoinPath(conf.BaseUrl, "api")) From 5697478c5df6a90559a9377af285c9a94c8e63bc Mon Sep 17 00:00:00 2001 From: barry Date: Sat, 22 Jun 2024 21:30:43 +0800 Subject: [PATCH 06/41] fix: 2024-06-22 21:30:43 --- cmds/app/cmd.go | 4 ++-- core/signal/signal.go | 16 ++++++++++++++++ pkg/gateway/internal/routertree/parser.go | 6 ++++-- pkg/gateway/internal/routertree/parser_test.go | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 pkg/gateway/internal/routertree/parser_test.go diff --git a/cmds/app/cmd.go b/cmds/app/cmd.go index 05152e0d..d9ec3f9f 100644 --- a/cmds/app/cmd.go +++ b/cmds/app/cmd.go @@ -1,7 +1,6 @@ package app import ( - "context" "os" "sort" @@ -24,6 +23,7 @@ import ( "github.com/pubgo/lava/core/logging" "github.com/pubgo/lava/core/metrics" "github.com/pubgo/lava/core/scheduler" + "github.com/pubgo/lava/core/signal" "github.com/pubgo/lava/internal/middlewares/middleware_accesslog" "github.com/pubgo/lava/internal/middlewares/middleware_metric" "github.com/pubgo/lava/pkg/cmdutil" @@ -103,6 +103,6 @@ func Run(di *dix.Dix) { } sort.Sort(cli.FlagsByName(app.Flags)) - assert.Must(app.Run(context.Background(), os.Args)) + assert.Must(app.Run(signal.Context(), os.Args)) }) } diff --git a/core/signal/signal.go b/core/signal/signal.go index deaec416..a13aa83f 100644 --- a/core/signal/signal.go +++ b/core/signal/signal.go @@ -1,6 +1,7 @@ package signal import ( + "context" "os" "os/signal" "syscall" @@ -18,3 +19,18 @@ func Wait() { sig := <-ch logger.Info().Str("signal", sig.String()).Msg("signal trigger notify") } + +func Context() context.Context { + ctx, cancel := context.WithCancel(context.Background()) + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGHUP) + go func() { + select { + case <-ch: + cancel() + case <-ctx.Done(): + cancel() + } + }() + return ctx +} diff --git a/pkg/gateway/internal/routertree/parser.go b/pkg/gateway/internal/routertree/parser.go index bd383f99..0dd98f56 100644 --- a/pkg/gateway/internal/routertree/parser.go +++ b/pkg/gateway/internal/routertree/parser.go @@ -18,7 +18,7 @@ const ( var ( parser = assert.Exit1(participle.Build[httpRule]( participle.Lexer(assert.Exit1(lexer.NewSimple([]lexer.SimpleRule{ - {Name: "Ident", Pattern: `[a-zA-Z]\w*`}, + {Name: "Ident", Pattern: `[a-zA-Z][\w\_\-\.]*`}, {Name: "Punct", Pattern: `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`}, }))), )) @@ -43,7 +43,7 @@ type segments struct { type segment struct { Path *string `@("*" "*" | "*" | Ident)` - Variable *variable `| @@` + Variable *variable `| @@*` } type variable struct { @@ -179,4 +179,6 @@ func parseToRoute(rule *httpRule) *routePath { func parse(url string) (*httpRule, error) { return parser.ParseString("", url) + //participle.AllowTrailing(true), + //participle.Trace(os.Stdout), } diff --git a/pkg/gateway/internal/routertree/parser_test.go b/pkg/gateway/internal/routertree/parser_test.go new file mode 100644 index 00000000..931feea8 --- /dev/null +++ b/pkg/gateway/internal/routertree/parser_test.go @@ -0,0 +1,16 @@ +package routertree + +import ( + "github.com/pubgo/funk/assert" + "testing" +) + +func TestName(t *testing.T) { + t.Log(parseToRoute(assert.Exit1(parse("/hello")))) + t.Log(parseToRoute(assert.Exit1(parse("/hello/world")))) + t.Log(parseToRoute(assert.Exit1(parse("/hello-world")))) + t.Log(parseToRoute(assert.Exit1(parse("/hello_world")))) + t.Log(parseToRoute(assert.Exit1(parse("/hello.world")))) + t.Log(parseToRoute(assert.Exit1(parse("/user.echo")))) + t.Log(parseToRoute(assert.Exit1(parse("/user.echo/{abc.abc}/hello")))) +} From d47a6339eccb646194482b37878e6eb52d05656e Mon Sep 17 00:00:00 2001 From: barry Date: Sat, 22 Jun 2024 21:30:52 +0800 Subject: [PATCH 07/41] fix: 2024-06-22 21:30:52 --- pkg/gateway/internal/routertree/parser_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/gateway/internal/routertree/parser_test.go b/pkg/gateway/internal/routertree/parser_test.go index 931feea8..a371a019 100644 --- a/pkg/gateway/internal/routertree/parser_test.go +++ b/pkg/gateway/internal/routertree/parser_test.go @@ -1,8 +1,9 @@ package routertree import ( - "github.com/pubgo/funk/assert" "testing" + + "github.com/pubgo/funk/assert" ) func TestName(t *testing.T) { From ab55c34f550eb1469f1e3ac09f8b31fb417519d7 Mon Sep 17 00:00:00 2001 From: barry Date: Sat, 29 Jun 2024 23:16:10 +0800 Subject: [PATCH 08/41] fix: 2024-06-29 23:16:10 --- go.mod | 4 +- go.sum | 12 +- pkg/proto/errcodepb/api.pb.go | 4 +- pkg/proto/errcodepb/api_grpc.pb.go | 2 +- pkg/proto/lavapbv1/event.pb.go | 4 +- pkg/proto/lavapbv1/form_file.pb.go | 4 +- pkg/proto/lavapbv1/rpc.pb.go | 185 +++++++++++++++++++++++ pkg/proto/lavapbv1/service.pb.go | 4 +- pkg/proto/metadatapb/metadata.pb.go | 4 +- pkg/proto/metadatapb/metadata_grpc.pb.go | 2 +- proto/lava/rpc.proto | 16 ++ protobuf.yaml | 4 +- 12 files changed, 225 insertions(+), 20 deletions(-) create mode 100644 pkg/proto/lavapbv1/rpc.pb.go create mode 100644 proto/lava/rpc.proto diff --git a/go.mod b/go.mod index 43ff7a21..9cce6360 100644 --- a/go.mod +++ b/go.mod @@ -62,9 +62,9 @@ require ( github.com/maragudk/gomponents v0.20.0 github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e github.com/pubgo/dix v0.3.15 - github.com/pubgo/funk v0.5.42 + github.com/pubgo/funk v0.5.45 github.com/rs/xid v1.5.0 - github.com/rs/zerolog v1.32.0 + github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.9.0 github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 github.com/tidwall/match v1.1.1 diff --git a/go.sum b/go.sum index eef6781a..3fd4f935 100644 --- a/go.sum +++ b/go.sum @@ -476,8 +476,8 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/pubgo/dix v0.3.15 h1:DLjXfnyhcxT3skM1pZi60i/QgnUEg9nM6CI8wom7gVc= github.com/pubgo/dix v0.3.15/go.mod h1:0j+i8YYn4vJnsJQCsyHXUGovR+Mgkh3uZPRhacw09us= -github.com/pubgo/funk v0.5.42 h1:/Z6agCcWLgYYmnPaUyhTf2FP9ZCiQIDA0lTSQyN1HZw= -github.com/pubgo/funk v0.5.42/go.mod h1:gKCw72+MK7xPiUGY1Z/bdGJMrSfVi87r0x/7d1GtKU4= +github.com/pubgo/funk v0.5.45 h1:9mfoi40ARbJWnjSGbGYXbBEHtwn4cbg8Ez0uYyoCaCg= +github.com/pubgo/funk v0.5.45/go.mod h1:Hm4oOYENrlr8A8nuH2YQWdx5jGg1fjAjaTvN2I28ts4= github.com/pubgo/opendoc v0.0.5 h1:aM6xkBQ0XMSq8OWytl5JhTMBUv8L+aYQFXd2z9eNkZE= github.com/pubgo/opendoc v0.0.5/go.mod h1:uO//pJZTJNFEKGuGWrv51/of0EoyxO1il4MuoC3Enp0= github.com/reugn/go-quartz v0.11.2 h1:+jc54Ji06n/D/endEPmc+CuG/Jc8466nda1oxtFRrks= @@ -492,8 +492,8 @@ github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= -github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 h1:KanIMPX0QdEdB4R3CiimCAbxFrhB3j7h0/OvpYGVQa8= github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg= @@ -535,8 +535,12 @@ github.com/testcontainers/testcontainers-go v0.30.0 h1:jmn/XS22q4YRrcMwWg0pAwlCl github.com/testcontainers/testcontainers-go v0.30.0/go.mod h1:K+kHNGiM5zjklKjgTtcrEetF3uhWbMUyqAQoyoh8Pf0= github.com/testcontainers/testcontainers-go/modules/postgres v0.30.0 h1:D3HFqpZS90iRGAN7M85DFiuhPfvYvFNnx8urQ6mPAvo= github.com/testcontainers/testcontainers-go/modules/postgres v0.30.0/go.mod h1:e1sKxwUOkqzvaqdHl/oV9mUtFmkDPTfBGp0po2tnWQU= +github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= +github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= diff --git a/pkg/proto/errcodepb/api.pb.go b/pkg/proto/errcodepb/api.pb.go index ae6660ce..b0c1a155 100644 --- a/pkg/proto/errcodepb/api.pb.go +++ b/pkg/proto/errcodepb/api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.3 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: proto/services/errcode/api.proto package errcodepb diff --git a/pkg/proto/errcodepb/api_grpc.pb.go b/pkg/proto/errcodepb/api_grpc.pb.go index 249cb30f..72a746ad 100644 --- a/pkg/proto/errcodepb/api_grpc.pb.go +++ b/pkg/proto/errcodepb/api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.3 +// - protoc v5.27.0 // source: proto/services/errcode/api.proto package errcodepb diff --git a/pkg/proto/lavapbv1/event.pb.go b/pkg/proto/lavapbv1/event.pb.go index dc9a7b89..46d5eec6 100644 --- a/pkg/proto/lavapbv1/event.pb.go +++ b/pkg/proto/lavapbv1/event.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.3 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: proto/lava/event.proto package lavapbv1 diff --git a/pkg/proto/lavapbv1/form_file.pb.go b/pkg/proto/lavapbv1/form_file.pb.go index da799e44..1c64b249 100644 --- a/pkg/proto/lavapbv1/form_file.pb.go +++ b/pkg/proto/lavapbv1/form_file.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.3 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: proto/lava/form_file.proto package lavapbv1 diff --git a/pkg/proto/lavapbv1/rpc.pb.go b/pkg/proto/lavapbv1/rpc.pb.go new file mode 100644 index 00000000..0e363d06 --- /dev/null +++ b/pkg/proto/lavapbv1/rpc.pb.go @@ -0,0 +1,185 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.1 +// protoc v5.27.0 +// source: proto/lava/rpc.proto + +package lavapbv1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + descriptorpb "google.golang.org/protobuf/types/descriptorpb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type RpcOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Version *string `protobuf:"bytes,2,opt,name=version,proto3,oneof" json:"version,omitempty"` +} + +func (x *RpcOptions) Reset() { + *x = RpcOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_lava_rpc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RpcOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RpcOptions) ProtoMessage() {} + +func (x *RpcOptions) ProtoReflect() protoreflect.Message { + mi := &file_proto_lava_rpc_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RpcOptions.ProtoReflect.Descriptor instead. +func (*RpcOptions) Descriptor() ([]byte, []int) { + return file_proto_lava_rpc_proto_rawDescGZIP(), []int{0} +} + +func (x *RpcOptions) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *RpcOptions) GetVersion() string { + if x != nil && x.Version != nil { + return *x.Version + } + return "" +} + +var file_proto_lava_rpc_proto_extTypes = []protoimpl.ExtensionInfo{ + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*RpcOptions)(nil), + Field: 100004, + Name: "lava.v1.options", + Tag: "bytes,100004,opt,name=options", + Filename: "proto/lava/rpc.proto", + }, +} + +// Extension fields to descriptorpb.MethodOptions. +var ( + // optional lava.v1.RpcOptions options = 100004; + E_Options = &file_proto_lava_rpc_proto_extTypes[0] +) + +var File_proto_lava_rpc_proto protoreflect.FileDescriptor + +var file_proto_lava_rpc_proto_rawDesc = []byte{ + 0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x72, 0x70, 0x63, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x76, 0x31, 0x1a, + 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x4b, 0x0a, 0x0a, 0x52, 0x70, 0x63, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, + 0x01, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x4f, + 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x13, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x70, 0x63, 0x4f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, + 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, + 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, 0x6c, 0x61, 0x76, 0x61, + 0x70, 0x62, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_lava_rpc_proto_rawDescOnce sync.Once + file_proto_lava_rpc_proto_rawDescData = file_proto_lava_rpc_proto_rawDesc +) + +func file_proto_lava_rpc_proto_rawDescGZIP() []byte { + file_proto_lava_rpc_proto_rawDescOnce.Do(func() { + file_proto_lava_rpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_lava_rpc_proto_rawDescData) + }) + return file_proto_lava_rpc_proto_rawDescData +} + +var file_proto_lava_rpc_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_proto_lava_rpc_proto_goTypes = []interface{}{ + (*RpcOptions)(nil), // 0: lava.v1.RpcOptions + (*descriptorpb.MethodOptions)(nil), // 1: google.protobuf.MethodOptions +} +var file_proto_lava_rpc_proto_depIdxs = []int32{ + 1, // 0: lava.v1.options:extendee -> google.protobuf.MethodOptions + 0, // 1: lava.v1.options:type_name -> lava.v1.RpcOptions + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 1, // [1:2] is the sub-list for extension type_name + 0, // [0:1] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_proto_lava_rpc_proto_init() } +func file_proto_lava_rpc_proto_init() { + if File_proto_lava_rpc_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_lava_rpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RpcOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_proto_lava_rpc_proto_msgTypes[0].OneofWrappers = []interface{}{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_lava_rpc_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 1, + NumServices: 0, + }, + GoTypes: file_proto_lava_rpc_proto_goTypes, + DependencyIndexes: file_proto_lava_rpc_proto_depIdxs, + MessageInfos: file_proto_lava_rpc_proto_msgTypes, + ExtensionInfos: file_proto_lava_rpc_proto_extTypes, + }.Build() + File_proto_lava_rpc_proto = out.File + file_proto_lava_rpc_proto_rawDesc = nil + file_proto_lava_rpc_proto_goTypes = nil + file_proto_lava_rpc_proto_depIdxs = nil +} diff --git a/pkg/proto/lavapbv1/service.pb.go b/pkg/proto/lavapbv1/service.pb.go index acd9e776..9d0f22e1 100644 --- a/pkg/proto/lavapbv1/service.pb.go +++ b/pkg/proto/lavapbv1/service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.3 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: proto/lava/service.proto package lavapbv1 diff --git a/pkg/proto/metadatapb/metadata.pb.go b/pkg/proto/metadatapb/metadata.pb.go index 2c3698f0..edd77593 100644 --- a/pkg/proto/metadatapb/metadata.pb.go +++ b/pkg/proto/metadatapb/metadata.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 -// protoc v4.25.3 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: proto/services/metadata/metadata.proto package metadatapb diff --git a/pkg/proto/metadatapb/metadata_grpc.pb.go b/pkg/proto/metadatapb/metadata_grpc.pb.go index ab476a5f..e1806efc 100644 --- a/pkg/proto/metadatapb/metadata_grpc.pb.go +++ b/pkg/proto/metadatapb/metadata_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.3 +// - protoc v5.27.0 // source: proto/services/metadata/metadata.proto package metadatapb diff --git a/proto/lava/rpc.proto b/proto/lava/rpc.proto new file mode 100644 index 00000000..809e07a1 --- /dev/null +++ b/proto/lava/rpc.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package lava.v1; + +import "google/protobuf/descriptor.proto"; + +option go_package = "github.com/pubgo/lava/pkg/proto/lavapbv1;lavapbv1"; + +message RpcOptions { + string name = 1; + optional string version = 2; +} + +extend google.protobuf.MethodOptions { + RpcOptions options = 100004; +} diff --git a/protobuf.yaml b/protobuf.yaml index 273670e2..90659ffd 100644 --- a/protobuf.yaml +++ b/protobuf.yaml @@ -1,4 +1,4 @@ -checksum: b55b45d0a21049cf1428cc849a514a13bad82d90 +checksum: 7420716c6267aaeccc1cedb3ff5beb63d54ad75a vendor: .proto base: out: ./pkg @@ -16,7 +16,7 @@ deps: - name: errorpb url: github.com/pubgo/funk path: /proto/errorpb - version: v0.5.42 + version: v0.5.45 plugins: - name: go - name: go-errors From 1645c684020fb72d2ae835b764e33a8b3717ca6c Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 30 Jun 2024 17:14:41 +0800 Subject: [PATCH 09/41] fix: 2024-06-30 17:14:41 --- .../grpc/pkg/proto/gidpb/id.errors.pb.go | 2 +- .../example/grpc/pkg/proto/gidpb/id.pb.go | 84 ++++++++++--------- .../grpc/pkg/proto/gidpb/id_grpc.pb.go | 2 +- internal/example/grpc/proto/gid/id.proto | 2 + internal/example/grpc/protobuf.yaml | 5 +- 5 files changed, 50 insertions(+), 45 deletions(-) diff --git a/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go index 5407980b..f49e957f 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-errors. DO NOT EDIT. // versions: // - protoc-gen-go-errors v0.0.5 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: gid/id.proto package gidpb diff --git a/internal/example/grpc/pkg/proto/gidpb/id.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.pb.go index fe26f1ef..0f9ab1c0 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc v5.27.0 // source: gid/id.proto package gidpb @@ -9,6 +9,7 @@ package gidpb import ( _ "github.com/google/gnostic-models/openapiv3" _ "github.com/pubgo/funk/proto/errorpb" + _ "github.com/pubgo/lava/pkg/proto/lavapbv1" _ "google.golang.org/genproto/googleapis/api/annotations" httpbody "google.golang.org/genproto/googleapis/api/httpbody" protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -527,7 +528,8 @@ var file_gid_id_proto_rawDesc = []byte{ 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x74, - 0x74, 0x70, 0x62, 0x6f, 0x64, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x6f, 0x70, + 0x74, 0x70, 0x62, 0x6f, 0x64, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0e, 0x6c, 0x61, + 0x76, 0x61, 0x2f, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x6f, 0x70, 0x65, 0x6e, 0x61, 0x70, 0x69, 0x76, 0x33, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x36, 0x0a, 0x10, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, @@ -567,48 +569,48 @@ var file_gid_id_proto_rawDesc = []byte{ 0x00, 0x12, 0x08, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x73, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x67, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x68, 0x6f, 0x72, - 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xf3, 0x04, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x53, 0x0a, 0x08, + 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xff, 0x04, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x5f, 0x0a, 0x08, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, - 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, - 0x65, 0x12, 0x4c, 0x0a, 0x0a, 0x54, 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, - 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, - 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, - 0x55, 0x0a, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, - 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, - 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, - 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, - 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, - 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x22, 0x3a, 0x01, 0x2a, 0x1a, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, - 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, - 0x69, 0x64, 0x7d, 0x12, 0x6f, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, - 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, - 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, - 0x3f, 0xba, 0x47, 0x27, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, - 0x74, 0x61, 0x67, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, - 0x61, 0x67, 0x31, 0x12, 0x06, 0xe8, 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x0f, 0x3a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, - 0x28, 0x01, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, - 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, - 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, - 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, - 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, - 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, - 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, - 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, - 0x2f, 0x67, 0x69, 0x64, 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x26, 0xa2, 0xea, 0x30, 0x08, 0x0a, 0x06, 0x69, 0x64, 0x2e, + 0x67, 0x65, 0x6e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x76, + 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x4c, 0x0a, + 0x0a, 0x54, 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x67, 0x69, + 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, + 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, + 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, 0x0a, 0x05, 0x54, + 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, + 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, + 0x64, 0x7d, 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, + 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, + 0x1a, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, + 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, + 0x6f, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, + 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, + 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0xba, 0x47, 0x27, + 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x0a, + 0x0e, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x31, 0x12, + 0x06, 0xe8, 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x3a, 0x03, 0x6d, + 0x73, 0x67, 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, 0x01, 0x30, 0x01, + 0x12, 0x31, 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, + 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, + 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, + 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x6f, 0x77, + 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, 0x70, 0x6c, 0x6f, + 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, + 0x6f, 0x64, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, 0x66, 0x69, 0x6c, + 0x65, 0x22, 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, 0x6c, 0x65, 0x6e, + 0x61, 0x6d, 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, + 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x67, 0x69, 0x64, + 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go index 2a9a6a46..c1569d91 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v5.26.1 +// - protoc v5.27.0 // source: gid/id.proto package gidpb diff --git a/internal/example/grpc/proto/gid/id.proto b/internal/example/grpc/proto/gid/id.proto index 34026926..826affd9 100644 --- a/internal/example/grpc/proto/gid/id.proto +++ b/internal/example/grpc/proto/gid/id.proto @@ -6,6 +6,7 @@ import "errorpb/options.proto"; import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/httpbody.proto"; +import "lava/rpc.proto"; import "openapiv3/annotations.proto"; option go_package = "./gidpb;gidpb"; @@ -23,6 +24,7 @@ service Id { // Generate 生成ID rpc Generate (GenerateRequest) returns (GenerateResponse) { + option (lava.rpc.options) = {name: "id.gen"}; option (google.api.http) = { post: "/v1/id/generate" body: "*" diff --git a/internal/example/grpc/protobuf.yaml b/internal/example/grpc/protobuf.yaml index cce954cc..6a624ee1 100644 --- a/internal/example/grpc/protobuf.yaml +++ b/internal/example/grpc/protobuf.yaml @@ -1,9 +1,10 @@ -checksum: db889045c39c093d2e967b4d457fa36fe2e0f420 +checksum: ea83f2fc3aa1588147f4bdaf251b3cd86fde7ca8 vendor: ../../../.proto root: - proto includes: - proto + - ../../../proto deps: - name: google url: github.com/googleapis/googleapis @@ -29,7 +30,7 @@ deps: - name: errorpb url: github.com/pubgo/funk path: /proto/errorpb - version: v0.5.42 + version: v0.5.45 plugins: - name: go out: pkg/proto From ac250197d0ecf99bd26afe2ed407f4cbe40542c6 Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 30 Jun 2024 17:14:54 +0800 Subject: [PATCH 10/41] fix: 2024-06-30 17:14:54 --- pkg/gateway/mux.go | 23 +++++++++++- pkg/gateway/util.go | 13 +++++++ pkg/gateway/wrapper.go | 16 +++++++- pkg/proto/lavapbv1/rpc.pb.go | 71 ++++++++++++++++++------------------ proto/lava/rpc.proto | 6 +-- 5 files changed, 87 insertions(+), 42 deletions(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 366901e1..dbe1dff5 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -140,6 +140,23 @@ func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ct m.opts.requestInterceptors[name] = f } +func (m *Mux) GetOperation(operation string) *GrpcMethod { + var opt = m.opts.handlers[operation] + if opt == nil { + return nil + } + + return &GrpcMethod{ + Srv: opt.srv.srv, + SrvDesc: opt.srv.serviceDesc, + GrpcMethodDesc: opt.grpcMethodDesc, + GrpcStreamDesc: opt.grpcStreamDesc, + MethodDesc: opt.grpcMethodPbDesc, + GrpcFullMethod: opt.grpcFullMethod, + Meta: opt.meta, + } +} + func (m *Mux) Handler(ctx *fiber.Ctx) error { matchOperation, err := m.routerTree.Match(ctx.Method(), string(ctx.Request().URI().Path())) if err != nil { @@ -314,9 +331,10 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcMethodDesc: grpcMth, grpcMethodPbDesc: methodDesc, grpcFullMethod: grpcMethod, + meta: getExtensionRpc(methodDesc), }) - assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { + assert.Exit(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod, resolveBodyDesc(methodDesc, reqBody, rspBody))) })) } @@ -333,9 +351,10 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { grpcStreamDesc: grpcMth, grpcMethodPbDesc: methodDesc, grpcFullMethod: grpcMethod, + meta: getExtensionRpc(methodDesc), }) - assert.Must(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { + assert.Exit(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { return errors.WrapCaller(m.routerTree.Add(mth, path, grpcMethod, resolveBodyDesc(methodDesc, reqBody, rspBody))) })) } diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index e313fb96..fe719613 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -12,6 +12,7 @@ import ( "github.com/pubgo/funk/assert" "github.com/pubgo/funk/errors" "github.com/pubgo/lava/pkg/gateway/internal/routertree" + "github.com/pubgo/lava/pkg/proto/lavapbv1" "google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" @@ -80,6 +81,18 @@ func getExtensionHTTP(m protoreflect.MethodDescriptor) *annotations.HttpRule { return nil } +func getExtensionRpc(m protoreflect.MethodDescriptor) *lavapbv1.RpcMeta { + if m == nil || m.Options() == nil { + return nil + } + + ext, ok := proto.GetExtension(m.Options(), lavapbv1.E_Rpc).(*lavapbv1.RpcMeta) + if ok { + return ext + } + return nil +} + func setOutgoingHeader(header http.Header, md metadata.MD) { for k, vs := range md { if isReservedHeader(k) { diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index f223b076..406928a9 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -2,17 +2,30 @@ package gateway import ( "github.com/pubgo/funk/errors" + "github.com/pubgo/lava/pkg/proto/lavapbv1" "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protoreflect" ) type serviceWrapper struct { opts *muxOptions - srv interface{} + srv any serviceDesc *grpc.ServiceDesc servicePbDesc protoreflect.ServiceDescriptor } +type GrpcMethod struct { + Srv any + SrvDesc *grpc.ServiceDesc + + GrpcMethodDesc *grpc.MethodDesc + GrpcStreamDesc *grpc.StreamDesc + MethodDesc protoreflect.MethodDescriptor + + GrpcFullMethod string + Meta *lavapbv1.RpcMeta +} + type methodWrapper struct { srv *serviceWrapper grpcMethodDesc *grpc.MethodDesc @@ -21,6 +34,7 @@ type methodWrapper struct { // /{ServiceName}/{MethodName} grpcFullMethod string + meta *lavapbv1.RpcMeta } func (h methodWrapper) Handle(stream grpc.ServerStream) error { diff --git a/pkg/proto/lavapbv1/rpc.pb.go b/pkg/proto/lavapbv1/rpc.pb.go index 0e363d06..f7091702 100644 --- a/pkg/proto/lavapbv1/rpc.pb.go +++ b/pkg/proto/lavapbv1/rpc.pb.go @@ -21,7 +21,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type RpcOptions struct { +type RpcMeta struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -30,8 +30,8 @@ type RpcOptions struct { Version *string `protobuf:"bytes,2,opt,name=version,proto3,oneof" json:"version,omitempty"` } -func (x *RpcOptions) Reset() { - *x = RpcOptions{} +func (x *RpcMeta) Reset() { + *x = RpcMeta{} if protoimpl.UnsafeEnabled { mi := &file_proto_lava_rpc_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -39,13 +39,13 @@ func (x *RpcOptions) Reset() { } } -func (x *RpcOptions) String() string { +func (x *RpcMeta) String() string { return protoimpl.X.MessageStringOf(x) } -func (*RpcOptions) ProtoMessage() {} +func (*RpcMeta) ProtoMessage() {} -func (x *RpcOptions) ProtoReflect() protoreflect.Message { +func (x *RpcMeta) ProtoReflect() protoreflect.Message { mi := &file_proto_lava_rpc_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -57,19 +57,19 @@ func (x *RpcOptions) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use RpcOptions.ProtoReflect.Descriptor instead. -func (*RpcOptions) Descriptor() ([]byte, []int) { +// Deprecated: Use RpcMeta.ProtoReflect.Descriptor instead. +func (*RpcMeta) Descriptor() ([]byte, []int) { return file_proto_lava_rpc_proto_rawDescGZIP(), []int{0} } -func (x *RpcOptions) GetName() string { +func (x *RpcMeta) GetName() string { if x != nil { return x.Name } return "" } -func (x *RpcOptions) GetVersion() string { +func (x *RpcMeta) GetVersion() string { if x != nil && x.Version != nil { return *x.Version } @@ -79,41 +79,40 @@ func (x *RpcOptions) GetVersion() string { var file_proto_lava_rpc_proto_extTypes = []protoimpl.ExtensionInfo{ { ExtendedType: (*descriptorpb.MethodOptions)(nil), - ExtensionType: (*RpcOptions)(nil), + ExtensionType: (*RpcMeta)(nil), Field: 100004, - Name: "lava.v1.options", - Tag: "bytes,100004,opt,name=options", + Name: "lava.rpc.rpc", + Tag: "bytes,100004,opt,name=rpc", Filename: "proto/lava/rpc.proto", }, } // Extension fields to descriptorpb.MethodOptions. var ( - // optional lava.v1.RpcOptions options = 100004; - E_Options = &file_proto_lava_rpc_proto_extTypes[0] + // optional lava.rpc.RpcMeta rpc = 100004; + E_Rpc = &file_proto_lava_rpc_proto_extTypes[0] ) var File_proto_lava_rpc_proto protoreflect.FileDescriptor var file_proto_lava_rpc_proto_rawDesc = []byte{ 0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x72, 0x70, 0x63, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x76, 0x31, 0x1a, - 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x4b, 0x0a, 0x0a, 0x52, 0x70, 0x63, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, - 0x01, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x4f, - 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x13, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x70, 0x63, 0x4f, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, - 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, - 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, 0x6c, 0x61, 0x76, 0x61, - 0x70, 0x62, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, + 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x48, 0x0a, 0x07, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, + 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x45, 0x0a, 0x03, + 0x72, 0x70, 0x63, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6c, 0x61, + 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x52, 0x03, + 0x72, 0x70, 0x63, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, + 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -130,12 +129,12 @@ func file_proto_lava_rpc_proto_rawDescGZIP() []byte { var file_proto_lava_rpc_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_proto_lava_rpc_proto_goTypes = []interface{}{ - (*RpcOptions)(nil), // 0: lava.v1.RpcOptions + (*RpcMeta)(nil), // 0: lava.rpc.RpcMeta (*descriptorpb.MethodOptions)(nil), // 1: google.protobuf.MethodOptions } var file_proto_lava_rpc_proto_depIdxs = []int32{ - 1, // 0: lava.v1.options:extendee -> google.protobuf.MethodOptions - 0, // 1: lava.v1.options:type_name -> lava.v1.RpcOptions + 1, // 0: lava.rpc.rpc:extendee -> google.protobuf.MethodOptions + 0, // 1: lava.rpc.rpc:type_name -> lava.rpc.RpcMeta 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 1, // [1:2] is the sub-list for extension type_name @@ -150,7 +149,7 @@ func file_proto_lava_rpc_proto_init() { } if !protoimpl.UnsafeEnabled { file_proto_lava_rpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RpcOptions); i { + switch v := v.(*RpcMeta); i { case 0: return &v.state case 1: diff --git a/proto/lava/rpc.proto b/proto/lava/rpc.proto index 809e07a1..7d742a20 100644 --- a/proto/lava/rpc.proto +++ b/proto/lava/rpc.proto @@ -1,16 +1,16 @@ syntax = "proto3"; -package lava.v1; +package lava.rpc; import "google/protobuf/descriptor.proto"; option go_package = "github.com/pubgo/lava/pkg/proto/lavapbv1;lavapbv1"; -message RpcOptions { +message RpcMeta { string name = 1; optional string version = 2; } extend google.protobuf.MethodOptions { - RpcOptions options = 100004; + RpcMeta rpc = 100004; } From 64d02fe0cb1bb8f2f06c58341698583b757a8180 Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 30 Jun 2024 20:50:59 +0800 Subject: [PATCH 11/41] fix: 2024-06-30 20:50:58 --- pkg/gateway/aaa.go | 1 + pkg/gateway/mux.go | 36 +++++++++++++++++++++++++++--------- pkg/gateway/util.go | 2 +- pkg/proto/lavapbv1/rpc.pb.go | 31 ++++++++++++++++--------------- proto/lava/rpc.proto | 2 +- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/pkg/gateway/aaa.go b/pkg/gateway/aaa.go index 493b3e13..5f0ec844 100644 --- a/pkg/gateway/aaa.go +++ b/pkg/gateway/aaa.go @@ -25,6 +25,7 @@ type ( SetResponseEncoder(protoreflect.FullName, func(ctx *fiber.Ctx, msg proto.Message) error) RegisterService(sd *grpc.ServiceDesc, ss interface{}) + GetOperation(operation string) *GrpcMethod Handler(*fiber.Ctx) error ServeHTTP(http.ResponseWriter, *http.Request) GetRouteMethods() []RouteOperation diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index dbe1dff5..c48ecfa4 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -46,6 +46,7 @@ type muxOptions struct { requestInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error responseInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error handlers map[string]*methodWrapper + actions map[string]*methodWrapper } // MuxOption is an option for a mux. @@ -67,6 +68,7 @@ var ( responseInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), requestInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), handlers: make(map[string]*methodWrapper), + actions: make(map[string]*methodWrapper), } defaultCodecs = map[string]Codec{ @@ -140,21 +142,22 @@ func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ct m.opts.requestInterceptors[name] = f } +func (m *Mux) GetOperationByName(name string) *GrpcMethod { + act := m.opts.actions[name] + if act != nil { + return nil + } + + return handleOperation(act) +} + func (m *Mux) GetOperation(operation string) *GrpcMethod { var opt = m.opts.handlers[operation] if opt == nil { return nil } - return &GrpcMethod{ - Srv: opt.srv.srv, - SrvDesc: opt.srv.serviceDesc, - GrpcMethodDesc: opt.grpcMethodDesc, - GrpcStreamDesc: opt.grpcStreamDesc, - MethodDesc: opt.grpcMethodPbDesc, - GrpcFullMethod: opt.grpcFullMethod, - Meta: opt.meta, - } + return handleOperation(opt) } func (m *Mux) Handler(ctx *fiber.Ctx) error { @@ -293,6 +296,9 @@ func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { func (m *Mux) registerRouter(rule *methodWrapper) { m.opts.handlers[rule.grpcFullMethod] = rule + if rule.meta != nil { + m.opts.actions[rule.meta.Name] = rule + } } func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { @@ -378,3 +384,15 @@ func GetRouterTarget(mux *Mux, kind, path string) (*MatchOperation, error) { return restTarget, nil } + +func handleOperation(opt *methodWrapper) *GrpcMethod { + return &GrpcMethod{ + Srv: opt.srv.srv, + SrvDesc: opt.srv.serviceDesc, + GrpcMethodDesc: opt.grpcMethodDesc, + GrpcStreamDesc: opt.grpcStreamDesc, + MethodDesc: opt.grpcMethodPbDesc, + GrpcFullMethod: opt.grpcFullMethod, + Meta: opt.meta, + } +} diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index fe719613..f005651f 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -86,7 +86,7 @@ func getExtensionRpc(m protoreflect.MethodDescriptor) *lavapbv1.RpcMeta { return nil } - ext, ok := proto.GetExtension(m.Options(), lavapbv1.E_Rpc).(*lavapbv1.RpcMeta) + ext, ok := proto.GetExtension(m.Options(), lavapbv1.E_Options).(*lavapbv1.RpcMeta) if ok { return ext } diff --git a/pkg/proto/lavapbv1/rpc.pb.go b/pkg/proto/lavapbv1/rpc.pb.go index f7091702..aaa6b15a 100644 --- a/pkg/proto/lavapbv1/rpc.pb.go +++ b/pkg/proto/lavapbv1/rpc.pb.go @@ -81,16 +81,16 @@ var file_proto_lava_rpc_proto_extTypes = []protoimpl.ExtensionInfo{ ExtendedType: (*descriptorpb.MethodOptions)(nil), ExtensionType: (*RpcMeta)(nil), Field: 100004, - Name: "lava.rpc.rpc", - Tag: "bytes,100004,opt,name=rpc", + Name: "lava.rpc.options", + Tag: "bytes,100004,opt,name=options", Filename: "proto/lava/rpc.proto", }, } // Extension fields to descriptorpb.MethodOptions. var ( - // optional lava.rpc.RpcMeta rpc = 100004; - E_Rpc = &file_proto_lava_rpc_proto_extTypes[0] + // optional lava.rpc.RpcMeta options = 100004; + E_Options = &file_proto_lava_rpc_proto_extTypes[0] ) var File_proto_lava_rpc_proto protoreflect.FileDescriptor @@ -104,15 +104,16 @@ var file_proto_lava_rpc_proto_rawDesc = []byte{ 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, - 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x45, 0x0a, 0x03, - 0x72, 0x70, 0x63, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6c, 0x61, - 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x52, 0x03, - 0x72, 0x70, 0x63, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, - 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x4d, 0x0a, 0x07, + 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x11, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, + 0x74, 0x61, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x33, 0x5a, 0x31, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, + 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, + 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -133,8 +134,8 @@ var file_proto_lava_rpc_proto_goTypes = []interface{}{ (*descriptorpb.MethodOptions)(nil), // 1: google.protobuf.MethodOptions } var file_proto_lava_rpc_proto_depIdxs = []int32{ - 1, // 0: lava.rpc.rpc:extendee -> google.protobuf.MethodOptions - 0, // 1: lava.rpc.rpc:type_name -> lava.rpc.RpcMeta + 1, // 0: lava.rpc.options:extendee -> google.protobuf.MethodOptions + 0, // 1: lava.rpc.options:type_name -> lava.rpc.RpcMeta 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 1, // [1:2] is the sub-list for extension type_name diff --git a/proto/lava/rpc.proto b/proto/lava/rpc.proto index 7d742a20..5a5420bb 100644 --- a/proto/lava/rpc.proto +++ b/proto/lava/rpc.proto @@ -12,5 +12,5 @@ message RpcMeta { } extend google.protobuf.MethodOptions { - RpcMeta rpc = 100004; + RpcMeta options = 100004; } From a5436f41fed8d31310b840b19eda2eedfd0f8683 Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 30 Jun 2024 20:55:00 +0800 Subject: [PATCH 12/41] fix: 2024-06-30 20:55:00 --- pkg/proto/errcodepb/api.pb.go | 100 +++++------ pkg/proto/errcodepb/api_grpc.pb.go | 4 +- pkg/proto/metadatapb/metadata.pb.go | 164 +++++++++--------- pkg/proto/metadatapb/metadata_grpc.pb.go | 4 +- proto/{ => lava}/services/errcode/api.proto | 0 .../services/metadata/metadata.proto | 0 6 files changed, 136 insertions(+), 136 deletions(-) rename proto/{ => lava}/services/errcode/api.proto (100%) rename proto/{ => lava}/services/metadata/metadata.proto (100%) diff --git a/pkg/proto/errcodepb/api.pb.go b/pkg/proto/errcodepb/api.pb.go index b0c1a155..342aa59b 100644 --- a/pkg/proto/errcodepb/api.pb.go +++ b/pkg/proto/errcodepb/api.pb.go @@ -2,7 +2,7 @@ // versions: // protoc-gen-go v1.34.1 // protoc v5.27.0 -// source: proto/services/errcode/api.proto +// source: proto/lava/services/errcode/api.proto package errcodepb @@ -34,7 +34,7 @@ type ErrCodes struct { func (x *ErrCodes) Reset() { *x = ErrCodes{} if protoimpl.UnsafeEnabled { - mi := &file_proto_services_errcode_api_proto_msgTypes[0] + mi := &file_proto_lava_services_errcode_api_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -47,7 +47,7 @@ func (x *ErrCodes) String() string { func (*ErrCodes) ProtoMessage() {} func (x *ErrCodes) ProtoReflect() protoreflect.Message { - mi := &file_proto_services_errcode_api_proto_msgTypes[0] + mi := &file_proto_lava_services_errcode_api_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -60,7 +60,7 @@ func (x *ErrCodes) ProtoReflect() protoreflect.Message { // Deprecated: Use ErrCodes.ProtoReflect.Descriptor instead. func (*ErrCodes) Descriptor() ([]byte, []int) { - return file_proto_services_errcode_api_proto_rawDescGZIP(), []int{0} + return file_proto_lava_services_errcode_api_proto_rawDescGZIP(), []int{0} } func (x *ErrCodes) GetCodes() []*errorpb.ErrCode { @@ -70,52 +70,52 @@ func (x *ErrCodes) GetCodes() []*errorpb.ErrCode { return nil } -var File_proto_services_errcode_api_proto protoreflect.FileDescriptor - -var file_proto_services_errcode_api_proto_rawDesc = []byte{ - 0x0a, 0x20, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x2f, 0x65, 0x72, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x12, 0x0c, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x1a, 0x14, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x70, 0x62, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x31, 0x0a, 0x08, 0x45, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x25, 0x0a, - 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2e, 0x45, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x63, - 0x6f, 0x64, 0x65, 0x73, 0x32, 0x60, 0x0a, 0x0c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x50, 0x0a, 0x05, 0x43, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x16, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x2e, 0x45, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x73, 0x22, 0x17, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x65, 0x72, 0x72, - 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, - 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x72, 0x72, 0x63, 0x6f, 0x64, - 0x65, 0x70, 0x62, 0x3b, 0x65, 0x72, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, +var File_proto_lava_services_errcode_api_proto protoreflect.FileDescriptor + +var file_proto_lava_services_errcode_api_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x65, 0x72, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x14, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x70, 0x62, 0x2f, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x31, 0x0a, 0x08, 0x45, 0x72, 0x72, 0x43, 0x6f, 0x64, + 0x65, 0x73, 0x12, 0x25, 0x0a, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2e, 0x45, 0x72, 0x72, 0x43, 0x6f, + 0x64, 0x65, 0x52, 0x05, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x32, 0x60, 0x0a, 0x0c, 0x45, 0x72, 0x72, + 0x6f, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x50, 0x0a, 0x05, 0x43, 0x6f, 0x64, + 0x65, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x6c, 0x61, 0x76, + 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x45, 0x72, 0x72, 0x43, 0x6f, 0x64, + 0x65, 0x73, 0x22, 0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x12, 0x0f, 0x2f, 0x6c, 0x61, 0x76, + 0x61, 0x2f, 0x65, 0x72, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x35, 0x5a, 0x33, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, + 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, + 0x72, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x70, 0x62, 0x3b, 0x65, 0x72, 0x72, 0x63, 0x6f, 0x64, 0x65, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proto_services_errcode_api_proto_rawDescOnce sync.Once - file_proto_services_errcode_api_proto_rawDescData = file_proto_services_errcode_api_proto_rawDesc + file_proto_lava_services_errcode_api_proto_rawDescOnce sync.Once + file_proto_lava_services_errcode_api_proto_rawDescData = file_proto_lava_services_errcode_api_proto_rawDesc ) -func file_proto_services_errcode_api_proto_rawDescGZIP() []byte { - file_proto_services_errcode_api_proto_rawDescOnce.Do(func() { - file_proto_services_errcode_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_services_errcode_api_proto_rawDescData) +func file_proto_lava_services_errcode_api_proto_rawDescGZIP() []byte { + file_proto_lava_services_errcode_api_proto_rawDescOnce.Do(func() { + file_proto_lava_services_errcode_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_lava_services_errcode_api_proto_rawDescData) }) - return file_proto_services_errcode_api_proto_rawDescData + return file_proto_lava_services_errcode_api_proto_rawDescData } -var file_proto_services_errcode_api_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proto_services_errcode_api_proto_goTypes = []interface{}{ +var file_proto_lava_services_errcode_api_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_proto_lava_services_errcode_api_proto_goTypes = []interface{}{ (*ErrCodes)(nil), // 0: lava.service.ErrCodes (*errorpb.ErrCode)(nil), // 1: errors.ErrCode (*emptypb.Empty)(nil), // 2: google.protobuf.Empty } -var file_proto_services_errcode_api_proto_depIdxs = []int32{ +var file_proto_lava_services_errcode_api_proto_depIdxs = []int32{ 1, // 0: lava.service.ErrCodes.codes:type_name -> errors.ErrCode 2, // 1: lava.service.ErrorService.Codes:input_type -> google.protobuf.Empty 0, // 2: lava.service.ErrorService.Codes:output_type -> lava.service.ErrCodes @@ -126,13 +126,13 @@ var file_proto_services_errcode_api_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_proto_services_errcode_api_proto_init() } -func file_proto_services_errcode_api_proto_init() { - if File_proto_services_errcode_api_proto != nil { +func init() { file_proto_lava_services_errcode_api_proto_init() } +func file_proto_lava_services_errcode_api_proto_init() { + if File_proto_lava_services_errcode_api_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_services_errcode_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_errcode_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ErrCodes); i { case 0: return &v.state @@ -149,18 +149,18 @@ func file_proto_services_errcode_api_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_services_errcode_api_proto_rawDesc, + RawDescriptor: file_proto_lava_services_errcode_api_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_services_errcode_api_proto_goTypes, - DependencyIndexes: file_proto_services_errcode_api_proto_depIdxs, - MessageInfos: file_proto_services_errcode_api_proto_msgTypes, + GoTypes: file_proto_lava_services_errcode_api_proto_goTypes, + DependencyIndexes: file_proto_lava_services_errcode_api_proto_depIdxs, + MessageInfos: file_proto_lava_services_errcode_api_proto_msgTypes, }.Build() - File_proto_services_errcode_api_proto = out.File - file_proto_services_errcode_api_proto_rawDesc = nil - file_proto_services_errcode_api_proto_goTypes = nil - file_proto_services_errcode_api_proto_depIdxs = nil + File_proto_lava_services_errcode_api_proto = out.File + file_proto_lava_services_errcode_api_proto_rawDesc = nil + file_proto_lava_services_errcode_api_proto_goTypes = nil + file_proto_lava_services_errcode_api_proto_depIdxs = nil } diff --git a/pkg/proto/errcodepb/api_grpc.pb.go b/pkg/proto/errcodepb/api_grpc.pb.go index 72a746ad..840d4ea9 100644 --- a/pkg/proto/errcodepb/api_grpc.pb.go +++ b/pkg/proto/errcodepb/api_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.3.0 // - protoc v5.27.0 -// source: proto/services/errcode/api.proto +// source: proto/lava/services/errcode/api.proto package errcodepb @@ -104,5 +104,5 @@ var ErrorService_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "proto/services/errcode/api.proto", + Metadata: "proto/lava/services/errcode/api.proto", } diff --git a/pkg/proto/metadatapb/metadata.pb.go b/pkg/proto/metadatapb/metadata.pb.go index edd77593..d3c71872 100644 --- a/pkg/proto/metadatapb/metadata.pb.go +++ b/pkg/proto/metadatapb/metadata.pb.go @@ -2,7 +2,7 @@ // versions: // protoc-gen-go v1.34.1 // protoc v5.27.0 -// source: proto/services/metadata/metadata.proto +// source: proto/lava/services/metadata/metadata.proto package metadatapb @@ -31,7 +31,7 @@ type ListServicesRequest struct { func (x *ListServicesRequest) Reset() { *x = ListServicesRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[0] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -44,7 +44,7 @@ func (x *ListServicesRequest) String() string { func (*ListServicesRequest) ProtoMessage() {} func (x *ListServicesRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[0] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -57,7 +57,7 @@ func (x *ListServicesRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ListServicesRequest.ProtoReflect.Descriptor instead. func (*ListServicesRequest) Descriptor() ([]byte, []int) { - return file_proto_services_metadata_metadata_proto_rawDescGZIP(), []int{0} + return file_proto_lava_services_metadata_metadata_proto_rawDescGZIP(), []int{0} } type ListServicesReply struct { @@ -72,7 +72,7 @@ type ListServicesReply struct { func (x *ListServicesReply) Reset() { *x = ListServicesReply{} if protoimpl.UnsafeEnabled { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[1] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -85,7 +85,7 @@ func (x *ListServicesReply) String() string { func (*ListServicesReply) ProtoMessage() {} func (x *ListServicesReply) ProtoReflect() protoreflect.Message { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[1] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -98,7 +98,7 @@ func (x *ListServicesReply) ProtoReflect() protoreflect.Message { // Deprecated: Use ListServicesReply.ProtoReflect.Descriptor instead. func (*ListServicesReply) Descriptor() ([]byte, []int) { - return file_proto_services_metadata_metadata_proto_rawDescGZIP(), []int{1} + return file_proto_lava_services_metadata_metadata_proto_rawDescGZIP(), []int{1} } func (x *ListServicesReply) GetServices() []string { @@ -126,7 +126,7 @@ type GetServiceDescRequest struct { func (x *GetServiceDescRequest) Reset() { *x = GetServiceDescRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[2] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -139,7 +139,7 @@ func (x *GetServiceDescRequest) String() string { func (*GetServiceDescRequest) ProtoMessage() {} func (x *GetServiceDescRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[2] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -152,7 +152,7 @@ func (x *GetServiceDescRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetServiceDescRequest.ProtoReflect.Descriptor instead. func (*GetServiceDescRequest) Descriptor() ([]byte, []int) { - return file_proto_services_metadata_metadata_proto_rawDescGZIP(), []int{2} + return file_proto_lava_services_metadata_metadata_proto_rawDescGZIP(), []int{2} } func (x *GetServiceDescRequest) GetName() string { @@ -173,7 +173,7 @@ type GetServiceDescReply struct { func (x *GetServiceDescReply) Reset() { *x = GetServiceDescReply{} if protoimpl.UnsafeEnabled { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[3] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -186,7 +186,7 @@ func (x *GetServiceDescReply) String() string { func (*GetServiceDescReply) ProtoMessage() {} func (x *GetServiceDescReply) ProtoReflect() protoreflect.Message { - mi := &file_proto_services_metadata_metadata_proto_msgTypes[3] + mi := &file_proto_lava_services_metadata_metadata_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -199,7 +199,7 @@ func (x *GetServiceDescReply) ProtoReflect() protoreflect.Message { // Deprecated: Use GetServiceDescReply.ProtoReflect.Descriptor instead. func (*GetServiceDescReply) Descriptor() ([]byte, []int) { - return file_proto_services_metadata_metadata_proto_rawDescGZIP(), []int{3} + return file_proto_lava_services_metadata_metadata_proto_rawDescGZIP(), []int{3} } func (x *GetServiceDescReply) GetFileDescSet() *descriptorpb.FileDescriptorSet { @@ -209,75 +209,75 @@ func (x *GetServiceDescReply) GetFileDescSet() *descriptorpb.FileDescriptorSet { return nil } -var File_proto_services_metadata_metadata_proto protoreflect.FileDescriptor - -var file_proto_services_metadata_metadata_proto_rawDesc = []byte{ - 0x0a, 0x26, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, - 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x15, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x49, 0x0a, - 0x11, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x70, - 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x18, - 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x2b, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5d, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x46, 0x0a, 0x0d, - 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x5f, 0x73, 0x65, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, - 0x70, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x0b, 0x66, 0x69, 0x6c, 0x65, 0x44, 0x65, 0x73, - 0x63, 0x53, 0x65, 0x74, 0x32, 0x82, 0x02, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x12, 0x73, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x73, 0x12, 0x21, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, - 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x12, 0x17, 0x2f, - 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x80, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x12, 0x23, 0x2e, 0x6c, 0x61, 0x76, 0x61, - 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, - 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, +var File_proto_lava_services_metadata_metadata_proto protoreflect.FileDescriptor + +var file_proto_lava_services_metadata_metadata_proto_rawDesc = []byte{ + 0x0a, 0x2b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x6c, + 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, + 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x15, 0x0a, 0x13, 0x4c, + 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x22, 0x49, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x2b, 0x0a, + 0x15, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5d, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x70, 0x6c, - 0x79, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x12, 0x1e, 0x2f, 0x6c, 0x61, 0x76, 0x61, - 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, - 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x70, 0x62, 0x3b, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x12, 0x46, 0x0a, 0x0d, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x5f, 0x73, + 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x44, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x0b, 0x66, 0x69, + 0x6c, 0x65, 0x44, 0x65, 0x73, 0x63, 0x53, 0x65, 0x74, 0x32, 0x82, 0x02, 0x0a, 0x08, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x73, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x21, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6c, 0x61, 0x76, 0x61, + 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x19, 0x12, 0x17, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x80, 0x01, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x12, 0x23, + 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, + 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x44, 0x65, 0x73, + 0x63, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x26, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x20, 0x12, 0x1e, + 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x37, + 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, + 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x70, 0x62, 0x3b, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proto_services_metadata_metadata_proto_rawDescOnce sync.Once - file_proto_services_metadata_metadata_proto_rawDescData = file_proto_services_metadata_metadata_proto_rawDesc + file_proto_lava_services_metadata_metadata_proto_rawDescOnce sync.Once + file_proto_lava_services_metadata_metadata_proto_rawDescData = file_proto_lava_services_metadata_metadata_proto_rawDesc ) -func file_proto_services_metadata_metadata_proto_rawDescGZIP() []byte { - file_proto_services_metadata_metadata_proto_rawDescOnce.Do(func() { - file_proto_services_metadata_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_services_metadata_metadata_proto_rawDescData) +func file_proto_lava_services_metadata_metadata_proto_rawDescGZIP() []byte { + file_proto_lava_services_metadata_metadata_proto_rawDescOnce.Do(func() { + file_proto_lava_services_metadata_metadata_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_lava_services_metadata_metadata_proto_rawDescData) }) - return file_proto_services_metadata_metadata_proto_rawDescData + return file_proto_lava_services_metadata_metadata_proto_rawDescData } -var file_proto_services_metadata_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_proto_services_metadata_metadata_proto_goTypes = []interface{}{ +var file_proto_lava_services_metadata_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_proto_lava_services_metadata_metadata_proto_goTypes = []interface{}{ (*ListServicesRequest)(nil), // 0: lava.service.ListServicesRequest (*ListServicesReply)(nil), // 1: lava.service.ListServicesReply (*GetServiceDescRequest)(nil), // 2: lava.service.GetServiceDescRequest (*GetServiceDescReply)(nil), // 3: lava.service.GetServiceDescReply (*descriptorpb.FileDescriptorSet)(nil), // 4: google.protobuf.FileDescriptorSet } -var file_proto_services_metadata_metadata_proto_depIdxs = []int32{ +var file_proto_lava_services_metadata_metadata_proto_depIdxs = []int32{ 4, // 0: lava.service.GetServiceDescReply.file_desc_set:type_name -> google.protobuf.FileDescriptorSet 0, // 1: lava.service.Metadata.ListServices:input_type -> lava.service.ListServicesRequest 2, // 2: lava.service.Metadata.GetServiceDesc:input_type -> lava.service.GetServiceDescRequest @@ -290,13 +290,13 @@ var file_proto_services_metadata_metadata_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_proto_services_metadata_metadata_proto_init() } -func file_proto_services_metadata_metadata_proto_init() { - if File_proto_services_metadata_metadata_proto != nil { +func init() { file_proto_lava_services_metadata_metadata_proto_init() } +func file_proto_lava_services_metadata_metadata_proto_init() { + if File_proto_lava_services_metadata_metadata_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_services_metadata_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListServicesRequest); i { case 0: return &v.state @@ -308,7 +308,7 @@ func file_proto_services_metadata_metadata_proto_init() { return nil } } - file_proto_services_metadata_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ListServicesReply); i { case 0: return &v.state @@ -320,7 +320,7 @@ func file_proto_services_metadata_metadata_proto_init() { return nil } } - file_proto_services_metadata_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetServiceDescRequest); i { case 0: return &v.state @@ -332,7 +332,7 @@ func file_proto_services_metadata_metadata_proto_init() { return nil } } - file_proto_services_metadata_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetServiceDescReply); i { case 0: return &v.state @@ -349,18 +349,18 @@ func file_proto_services_metadata_metadata_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_services_metadata_metadata_proto_rawDesc, + RawDescriptor: file_proto_lava_services_metadata_metadata_proto_rawDesc, NumEnums: 0, NumMessages: 4, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_services_metadata_metadata_proto_goTypes, - DependencyIndexes: file_proto_services_metadata_metadata_proto_depIdxs, - MessageInfos: file_proto_services_metadata_metadata_proto_msgTypes, + GoTypes: file_proto_lava_services_metadata_metadata_proto_goTypes, + DependencyIndexes: file_proto_lava_services_metadata_metadata_proto_depIdxs, + MessageInfos: file_proto_lava_services_metadata_metadata_proto_msgTypes, }.Build() - File_proto_services_metadata_metadata_proto = out.File - file_proto_services_metadata_metadata_proto_rawDesc = nil - file_proto_services_metadata_metadata_proto_goTypes = nil - file_proto_services_metadata_metadata_proto_depIdxs = nil + File_proto_lava_services_metadata_metadata_proto = out.File + file_proto_lava_services_metadata_metadata_proto_rawDesc = nil + file_proto_lava_services_metadata_metadata_proto_goTypes = nil + file_proto_lava_services_metadata_metadata_proto_depIdxs = nil } diff --git a/pkg/proto/metadatapb/metadata_grpc.pb.go b/pkg/proto/metadatapb/metadata_grpc.pb.go index e1806efc..09554ac6 100644 --- a/pkg/proto/metadatapb/metadata_grpc.pb.go +++ b/pkg/proto/metadatapb/metadata_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.3.0 // - protoc v5.27.0 -// source: proto/services/metadata/metadata.proto +// source: proto/lava/services/metadata/metadata.proto package metadatapb @@ -144,5 +144,5 @@ var Metadata_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "proto/services/metadata/metadata.proto", + Metadata: "proto/lava/services/metadata/metadata.proto", } diff --git a/proto/services/errcode/api.proto b/proto/lava/services/errcode/api.proto similarity index 100% rename from proto/services/errcode/api.proto rename to proto/lava/services/errcode/api.proto diff --git a/proto/services/metadata/metadata.proto b/proto/lava/services/metadata/metadata.proto similarity index 100% rename from proto/services/metadata/metadata.proto rename to proto/lava/services/metadata/metadata.proto From 9b9db20fe4b7964967a2f91e8aeadae46e557b33 Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 30 Jun 2024 21:58:36 +0800 Subject: [PATCH 13/41] fix: 2024-06-30 21:58:36 --- pkg/gateway/mux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index c48ecfa4..2f4ce6b6 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -144,7 +144,7 @@ func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ct func (m *Mux) GetOperationByName(name string) *GrpcMethod { act := m.opts.actions[name] - if act != nil { + if act == nil { return nil } From f7ac2c4fd7fdfb20d8d0750f06513f2e120e50ee Mon Sep 17 00:00:00 2001 From: barry Date: Sun, 7 Jul 2024 10:26:30 +0800 Subject: [PATCH 14/41] fix route match --- pkg/gateway/internal/routertree/router.go | 10 ++++++++-- .../internal/routertree/router_test.go | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 pkg/gateway/internal/routertree/router_test.go diff --git a/pkg/gateway/internal/routertree/router.go b/pkg/gateway/internal/routertree/router.go index aaa692fb..bb6b7577 100644 --- a/pkg/gateway/internal/routertree/router.go +++ b/pkg/gateway/internal/routertree/router.go @@ -41,7 +41,8 @@ func (r *RouteTree) Add(method string, path string, operation string, extras map } var nodes = r.nodes - for i, n := range node.Paths { + paths := append(node.Paths, handlerMethod(method)) + for i, n := range paths { var lastNode = nodes[n] if lastNode == nil { lastNode = &nodeTree{nodes: make(map[string]*nodeTree), verbs: make(map[string]*routeTarget)} @@ -49,7 +50,7 @@ func (r *RouteTree) Add(method string, path string, operation string, extras map } nodes = lastNode.nodes - if i == len(node.Paths)-1 { + if i == len(paths)-1 { lastNode.verbs[generic.FromPtr(node.Verb)] = &routeTarget{ Method: method, Path: path, @@ -76,6 +77,7 @@ func (r *RouteTree) Match(method, url string) (*MatchOperation, error) { verb = lastPath[1] } + paths = append(paths, handlerMethod(method)) var getVars = func(vars []*pathVariable, paths []string) []PathFieldVar { var vv = make([]PathFieldVar, 0, len(vars)) for _, v := range vars { @@ -174,3 +176,7 @@ func getOpt(nodes map[string]*nodeTree) []RouteOperation { } return sets } + +func handlerMethod(method string) string { + return fmt.Sprintf("__%s__", strings.ToUpper(method)) +} diff --git a/pkg/gateway/internal/routertree/router_test.go b/pkg/gateway/internal/routertree/router_test.go new file mode 100644 index 00000000..19d23f4f --- /dev/null +++ b/pkg/gateway/internal/routertree/router_test.go @@ -0,0 +1,19 @@ +package routertree + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRoute(t *testing.T) { + tree := NewRouteTree() + assert.NoError(t, tree.Add("get", "/user/user/{id}:get1", "get_user", nil)) + assert.NoError(t, tree.Add("post", "/user/user/{id}", "post_user", nil)) + assert.NoError(t, tree.Add("post", "/user/user/{id}/send_mail", "post_mail", nil)) + opt, err := tree.Match("get", "/user/user/1:get1") + assert.NoError(t, err) + assert.NotNil(t, opt) + assert.Equal(t, "get_user", opt.Operation) + assert.Equal(t, "get1", opt.Verb) +} From fe0709eed73869599376b365e47a9d1f9c641433 Mon Sep 17 00:00:00 2001 From: barry Date: Thu, 11 Jul 2024 22:55:25 +0800 Subject: [PATCH 15/41] fix: barry 2024-07-11 22:55:24 --- pkg/gateway/mux.go | 1 + pkg/gateway/stream_http.go | 56 ++++++++++++++++++++++----------- pkg/gateway/stream_inprocess.go | 48 ++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 pkg/gateway/stream_inprocess.go diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 2f4ce6b6..eb3c90cc 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -206,6 +206,7 @@ func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts . } func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { + desc.Handler(new(methodWrapper).srv.srv, new(serverInProcess)) return m.cc.NewStream(ctx, desc, method, opts...) } diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index c6af1b14..9695539a 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -9,6 +9,7 @@ import ( "github.com/gofiber/fiber/v2" "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" "github.com/pubgo/funk/errors" + "github.com/pubgo/funk/generic" "github.com/pubgo/lava/pkg/gateway/internal/routertree" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -59,18 +60,21 @@ func (s *streamHTTP) SetTrailer(md metadata.MD) { func (s *streamHTTP) Context() context.Context { return grpc.NewContextWithServerTransportStream( s.ctx, - &serverTransportStream{ - ServerStream: s, - method: s.method.grpcFullMethod, - }, + &serverTransportStream{ServerStream: s, method: s.method.grpcFullMethod}, ) } func (s *streamHTTP) SendMsg(m interface{}) error { - reply := m.(proto.Message) + if generic.IsNil(m) { + return errors.New("stream http send msg got nil") + } + + reply, ok := m.(proto.Message) + if !ok { + return errors.New("stream http send proto msg got unknown type message") + } - fRsp, ok := s.handler.Response().BodyWriter().(http.Flusher) - if ok { + if fRsp, ok := s.handler.Response().BodyWriter().(http.Flusher); ok { defer fRsp.Flush() } @@ -88,7 +92,7 @@ func (s *streamHTTP) SendMsg(m interface{}) error { b, err := protojson.Marshal(msg) if err != nil { - return errors.Wrap(err, "failed to marshal response by protojson") + return errors.Wrap(err, "failed to marshal response by proto-json") } _, err = s.handler.Write(b) @@ -96,12 +100,21 @@ func (s *streamHTTP) SendMsg(m interface{}) error { } func (s *streamHTTP) RecvMsg(m interface{}) error { - args := m.(proto.Message) + if generic.IsNil(m) { + return errors.New("stream http recv msg got nil") + } + + args, ok := m.(proto.Message) + if !ok { + return errors.New("stream http recv proto msg got unknown type message") + } + + var method = s.handler.Method() - if s.handler.Method() == http.MethodPut || - s.handler.Method() == http.MethodPost || - s.handler.Method() == http.MethodDelete || - s.handler.Method() == http.MethodPatch { + if method == http.MethodPut || + method == http.MethodPost || + method == http.MethodDelete || + method == http.MethodPatch { cur := args.ProtoReflect() for _, fd := range getRspBodyDesc(s.path) { cur = cur.Mutable(fd).Message() @@ -114,15 +127,22 @@ func (s *streamHTTP) RecvMsg(m interface{}) error { return errors.Wrapf(handler(s.handler, msg), "failed to handler request data by %s", reqName) } - if s.handler.Body() != nil && len(s.handler.Body()) != 0 { - err := protojson.Unmarshal(s.handler.Body(), msg) - if err != nil { - return errors.Wrap(err, "failed to unmarshal body by protojson") + if method == http.MethodPut || + method == http.MethodPost || + method == http.MethodPatch { + if len(s.handler.Body()) == 0 { + return errors.WrapCaller(fmt.Errorf("request body is nil, operation=%s", reqName)) + } + } + + if len(s.handler.Body()) > 0 { + if err := protojson.Unmarshal(s.handler.Body(), msg); err != nil { + return errors.Wrap(err, "failed to unmarshal body by proto-json") } } } - if s.params != nil && len(s.params) > 0 { + if len(s.params) > 0 { if err := PopulateQueryParameters(args, s.params, utilities.NewDoubleArray(nil)); err != nil { return errors.Wrapf(err, "failed to set query params, params=%v", s.params) } diff --git a/pkg/gateway/stream_inprocess.go b/pkg/gateway/stream_inprocess.go new file mode 100644 index 00000000..07bc3010 --- /dev/null +++ b/pkg/gateway/stream_inprocess.go @@ -0,0 +1,48 @@ +package gateway + +import ( + "context" + + "github.com/fullstorydev/grpchan/inprocgrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var _ grpc.ServerStream = (*serverInProcess)(nil) + +type serverInProcess struct { + ctx context.Context + method string + args any + reply any + opts []grpc.CallOption + desc *grpc.StreamDesc +} + +func (s serverInProcess) SetHeader(md metadata.MD) error { + //TODO implement me + panic("implement me") +} + +func (s serverInProcess) SendHeader(md metadata.MD) error { + //TODO implement me + panic("implement me") +} + +func (s serverInProcess) SetTrailer(md metadata.MD) { + //TODO implement me + panic("implement me") +} + +func (s serverInProcess) Context() context.Context { + return s.ctx +} + +func (s serverInProcess) SendMsg(m any) error { + s.reply = m + return nil +} + +func (s serverInProcess) RecvMsg(m any) error { + return inprocgrpc.ProtoCloner{}.Copy(m, s.args) +} From e9cd352b2e28fa7b34170b48b85bb53ee2cce05c Mon Sep 17 00:00:00 2001 From: barry Date: Thu, 11 Jul 2024 23:26:11 +0800 Subject: [PATCH 16/41] fix: barry 2024-07-11 23:26:11 --- clients/resty/client.go | 2 +- core/metrics/context.go | 4 +-- core/metrics/drivers/prometheus/reporter.go | 6 +++-- core/metrics/factory.go | 8 +++--- core/metrics/metric.go | 5 ++-- go.mod | 14 +++++----- go.sum | 30 +++++++++++---------- 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/clients/resty/client.go b/clients/resty/client.go index 502df6fc..c9d5d01f 100644 --- a/clients/resty/client.go +++ b/clients/resty/client.go @@ -11,9 +11,9 @@ import ( "github.com/pubgo/funk/recovery" "github.com/pubgo/funk/result" "github.com/pubgo/funk/retry" - "github.com/pubgo/lava/core/metrics" "github.com/valyala/fasthttp" + "github.com/pubgo/lava/core/metrics" "github.com/pubgo/lava/internal/middlewares/middleware_accesslog" "github.com/pubgo/lava/internal/middlewares/middleware_metric" "github.com/pubgo/lava/internal/middlewares/middleware_recovery" diff --git a/core/metrics/context.go b/core/metrics/context.go index 01e78f79..9f8d804b 100644 --- a/core/metrics/context.go +++ b/core/metrics/context.go @@ -11,11 +11,11 @@ type ctxKet string var metricKey = ctxKet(xid.New().String()) -func CreateCtx(parent context.Context, scope tally.Scope) context.Context { +func InjectToCtx(parent context.Context, scope tally.Scope) context.Context { return context.WithValue(parent, metricKey, scope) } -func Ctx(ctx context.Context) tally.Scope { +func GetFromCtx(ctx context.Context) tally.Scope { l, ok := ctx.Value(metricKey).(tally.Scope) if ok { return l diff --git a/core/metrics/drivers/prometheus/reporter.go b/core/metrics/drivers/prometheus/reporter.go index 16524d7d..d3ab55c8 100644 --- a/core/metrics/drivers/prometheus/reporter.go +++ b/core/metrics/drivers/prometheus/reporter.go @@ -1,6 +1,7 @@ package prometheus import ( + "github.com/prometheus/common/model" "github.com/pubgo/funk/assert" "github.com/pubgo/funk/log" tally "github.com/uber-go/tally/v4" @@ -26,7 +27,8 @@ func New(conf *metrics.Config, log log.Logger) *tally.ScopeOptions { opts := tally.ScopeOptions{} opts.Separator = prometheus.DefaultSeparator - // opts.SanitizeOptions = &prometheus.DefaultSanitizerOpts + //opts.SanitizeOptions = &prometheus.DefaultSanitizerOpts + model.NameValidationScheme = model.UTF8Validation proCfg := &prometheus.Configuration{TimerType: "histogram"} @@ -34,7 +36,7 @@ func New(conf *metrics.Config, log log.Logger) *tally.ScopeOptions { assert.Must(conf.DriverCfg.Decode(proCfg)) } - logs := log.WithName(metrics.Name).WithName(Name) + logs := log.WithName(Name) reporter := assert.Must1(proCfg.NewReporter( prometheus.ConfigurationOptions{ OnError: func(err error) { diff --git a/core/metrics/factory.go b/core/metrics/factory.go index 48e8688b..0c23e15d 100644 --- a/core/metrics/factory.go +++ b/core/metrics/factory.go @@ -9,9 +9,9 @@ var factories = make(map[string]Factory) func Get(name string) Factory { return factories[name] } func List() map[string]Factory { return factories } -func Register(name string, broker Factory) { +func Register(name string, driver Factory) { defer recovery.Exit() - assert.If(name == "" || broker == nil, "[broker,name] should not be null") - assert.If(factories[name] != nil, "[broker] %s already exists", name) - factories[name] = broker + assert.If(name == "" || driver == nil, "[driver,name] should not be null") + assert.If(factories[name] != nil, "[driver] %s already exists", name) + factories[name] = driver } diff --git a/core/metrics/metric.go b/core/metrics/metric.go index ae11608c..030cc942 100644 --- a/core/metrics/metric.go +++ b/core/metrics/metric.go @@ -6,6 +6,7 @@ import ( "github.com/pubgo/funk/log" "github.com/pubgo/funk/merge" "github.com/pubgo/funk/version" + lo "github.com/samber/lo" "github.com/uber-go/tally/v4" "github.com/pubgo/lava/core/lifecycle" @@ -18,14 +19,14 @@ func New(m lifecycle.Lifecycle, cfg *Config, log log.Logger) Metric { factory := Get(cfg.Driver) assert.If(factory == nil, "driver factory[%s] not found", cfg.Driver) - opts := factory(cfg, log) + opts := factory(cfg, log.WithName("driver")) if opts == nil { return tally.NoopScope } opts.Tags = Tags{"project": version.Project()} - scope, closer := tally.NewRootScope(*opts, cfg.Interval) + scope, closer := tally.NewRootScope(lo.FromPtr(opts), cfg.Interval) m.BeforeStop(func() { assert.Must(closer.Close()) }) registerVars(scope) diff --git a/go.mod b/go.mod index 9cce6360..49e88b8e 100644 --- a/go.mod +++ b/go.mod @@ -22,10 +22,10 @@ require ( go.opentelemetry.io/otel/trace v1.26.0 go.uber.org/atomic v1.10.0 // indirect go.uber.org/automaxprocs v1.5.3 - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.24.0 - golang.org/x/sys v0.19.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 + golang.org/x/sys v0.20.0 // indirect google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.1 ) @@ -65,6 +65,7 @@ require ( github.com/pubgo/funk v0.5.45 github.com/rs/xid v1.5.0 github.com/rs/zerolog v1.33.0 + github.com/samber/lo v1.44.0 github.com/stretchr/testify v1.9.0 github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 github.com/tidwall/match v1.1.1 @@ -190,8 +191,9 @@ require ( go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/proto/otlp v1.2.0 // indirect golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.18.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/text v0.16.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect gorm.io/datatypes v1.0.7 // indirect gorm.io/hints v1.1.0 // indirect diff --git a/go.sum b/go.sum index 3fd4f935..d2f60c7b 100644 --- a/go.sum +++ b/go.sum @@ -494,6 +494,8 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA= +github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 h1:KanIMPX0QdEdB4R3CiimCAbxFrhB3j7h0/OvpYGVQa8= github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg= @@ -641,8 +643,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= @@ -655,8 +657,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 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-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -679,8 +681,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -691,8 +693,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -731,8 +733,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 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= @@ -742,8 +744,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -764,8 +766,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From f62b70914d13806c15f6ea84b24356da30deb7ac Mon Sep 17 00:00:00 2001 From: barry Date: Thu, 11 Jul 2024 23:32:03 +0800 Subject: [PATCH 17/41] fix: barry 2024-07-11 23:32:03 --- .../example/grpc/internal/handlers/gid_handler/handler_grpc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go b/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go index 15f4cbd3..8fffdc9e 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go @@ -51,6 +51,8 @@ func (id *Id) PutTypes(ctx context.Context, req *gidpb.TypesRequest) (*gidpb.Typ "snowflake", "bigflake", } + var req1 = resty.NewRequest(typesReq) + id.service.IClient.Do(nil, req1) return rsp, nil } From c02cc8cbc5c095c0845d4f4d48b31ef22ade24eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 10:48:34 +0800 Subject: [PATCH 18/41] fix: barry 2024-07-13 10:48:34 --- pkg/gateway/_doc.go | 1 + pkg/gateway/mux.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gateway/_doc.go b/pkg/gateway/_doc.go index 9d76f814..80741a4c 100644 --- a/pkg/gateway/_doc.go +++ b/pkg/gateway/_doc.go @@ -11,3 +11,4 @@ package gateway // github.com/improbable-eng/grpc-web // github.com/grpc-ecosystem/grpc-gateway/v2 // https://github.com/nhooyr/websocket +// https://github.com/connectrpc/vanguard-go diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index eb3c90cc..2f4ce6b6 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -206,7 +206,6 @@ func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts . } func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { - desc.Handler(new(methodWrapper).srv.srv, new(serverInProcess)) return m.cc.NewStream(ctx, desc, method, opts...) } From a58e527cd3109a607e25ffc03a501a3b3cc80b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 11:17:28 +0800 Subject: [PATCH 19/41] fix: barry 2024-07-13 11:17:28 --- pkg/gateway/mux.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 2f4ce6b6..22be4a0e 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -3,6 +3,7 @@ package gateway import ( "context" "fmt" + "github.com/pubgo/funk/result" "math" "net/http" "net/url" @@ -46,7 +47,7 @@ type muxOptions struct { requestInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error responseInterceptors map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error handlers map[string]*methodWrapper - actions map[string]*methodWrapper + customOperationNames map[string]*methodWrapper } // MuxOption is an option for a mux. @@ -68,7 +69,7 @@ var ( responseInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), requestInterceptors: make(map[protoreflect.FullName]func(ctx *fiber.Ctx, msg proto.Message) error), handlers: make(map[string]*methodWrapper), - actions: make(map[string]*methodWrapper), + customOperationNames: make(map[string]*methodWrapper), } defaultCodecs = map[string]Codec{ @@ -142,8 +143,17 @@ func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx *fiber.Ct m.opts.requestInterceptors[name] = f } +func (m *Mux) MatchOperation(method string, path string) (r result.Result[*MatchOperation]) { + restTarget, err := m.routerTree.Match(method, path) + if err != nil { + return r.WithErr(errors.Wrapf(err, "path not found, method=%s path=%s", method, path)) + } + + return r.WithVal(restTarget) +} + func (m *Mux) GetOperationByName(name string) *GrpcMethod { - act := m.opts.actions[name] + act := m.opts.customOperationNames[name] if act == nil { return nil } @@ -151,6 +161,14 @@ func (m *Mux) GetOperationByName(name string) *GrpcMethod { return handleOperation(act) } +func (m *Mux) HandleStream(operation string, stream grpc.ServerStream) error { + mth := m.opts.handlers[operation] + if mth == nil { + return errors.Format("grpc method not found, method=%s", operation) + } + return errors.WrapCaller(mth.Handle(stream)) +} + func (m *Mux) GetOperation(operation string) *GrpcMethod { var opt = m.opts.handlers[operation] if opt == nil { @@ -297,7 +315,7 @@ func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { func (m *Mux) registerRouter(rule *methodWrapper) { m.opts.handlers[rule.grpcFullMethod] = rule if rule.meta != nil { - m.opts.actions[rule.meta.Name] = rule + m.opts.customOperationNames[rule.meta.Name] = rule } } From 5ed78e6050de8b4587634a42ec86f35bbb075c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 11:22:01 +0800 Subject: [PATCH 20/41] fix: barry 2024-07-13 11:22:01 --- .../{stream_transport.go => server_transport_stream.go} | 6 ++++++ pkg/gateway/stream_http.go | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) rename pkg/gateway/{stream_transport.go => server_transport_stream.go} (74%) diff --git a/pkg/gateway/stream_transport.go b/pkg/gateway/server_transport_stream.go similarity index 74% rename from pkg/gateway/stream_transport.go rename to pkg/gateway/server_transport_stream.go index 73a4ca3f..862da265 100644 --- a/pkg/gateway/stream_transport.go +++ b/pkg/gateway/server_transport_stream.go @@ -1,12 +1,18 @@ package gateway import ( + "context" + "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) var _ grpc.ServerTransportStream = (*serverTransportStream)(nil) +func NewContextWithServerTransportStream(ctx context.Context, s grpc.ServerStream, method string) context.Context { + return grpc.NewContextWithServerTransportStream(ctx, &serverTransportStream{ServerStream: s, method: method}) +} + // serverTransportStream wraps grpc.SeverStream to support header/trailers. type serverTransportStream struct { grpc.ServerStream diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index 9695539a..d3bc3699 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -58,10 +58,7 @@ func (s *streamHTTP) SetTrailer(md metadata.MD) { } func (s *streamHTTP) Context() context.Context { - return grpc.NewContextWithServerTransportStream( - s.ctx, - &serverTransportStream{ServerStream: s, method: s.method.grpcFullMethod}, - ) + return NewContextWithServerTransportStream(s.ctx, s, s.method.grpcFullMethod) } func (s *streamHTTP) SendMsg(m interface{}) error { From dcdf2a19d65236cfc2e1a94377af5b04fc4215e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 11:24:17 +0800 Subject: [PATCH 21/41] fix: barry 2024-07-13 11:24:17 --- pkg/gateway/server_transport_stream.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/gateway/server_transport_stream.go b/pkg/gateway/server_transport_stream.go index 862da265..31b084f9 100644 --- a/pkg/gateway/server_transport_stream.go +++ b/pkg/gateway/server_transport_stream.go @@ -3,6 +3,7 @@ package gateway import ( "context" + "github.com/pubgo/funk/assert" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -10,6 +11,9 @@ import ( var _ grpc.ServerTransportStream = (*serverTransportStream)(nil) func NewContextWithServerTransportStream(ctx context.Context, s grpc.ServerStream, method string) context.Context { + assert.If(ctx == nil, "ctx is nil") + assert.If(s == nil, "server stream is nil") + assert.If(method == "", "method is nil") return grpc.NewContextWithServerTransportStream(ctx, &serverTransportStream{ServerStream: s, method: method}) } From 7a1beffd1f186f2b1d866f8c83919bf42cd20781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 19:46:35 +0800 Subject: [PATCH 22/41] fix: barry 2024-07-13 19:46:35 --- pkg/gateway/_doc.go | 1 + pkg/gateway/mux.go | 2 +- pkg/gateway/stream_grpc.go | 1 + pkg/gateway/stream_grpcweb.go | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 pkg/gateway/stream_grpc.go create mode 100644 pkg/gateway/stream_grpcweb.go diff --git a/pkg/gateway/_doc.go b/pkg/gateway/_doc.go index 80741a4c..3a62f359 100644 --- a/pkg/gateway/_doc.go +++ b/pkg/gateway/_doc.go @@ -12,3 +12,4 @@ package gateway // github.com/grpc-ecosystem/grpc-gateway/v2 // https://github.com/nhooyr/websocket // https://github.com/connectrpc/vanguard-go +// https://github.com/emcfarlane/larking diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 22be4a0e..27ca24d5 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -3,7 +3,6 @@ package gateway import ( "context" "fmt" - "github.com/pubgo/funk/result" "math" "net/http" "net/url" @@ -19,6 +18,7 @@ import ( "github.com/pubgo/funk/errors" "github.com/pubgo/funk/generic" "github.com/pubgo/funk/log" + "github.com/pubgo/funk/result" "github.com/pubgo/funk/version" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/gateway/internal/routertree" diff --git a/pkg/gateway/stream_grpc.go b/pkg/gateway/stream_grpc.go new file mode 100644 index 00000000..fa0ed3c2 --- /dev/null +++ b/pkg/gateway/stream_grpc.go @@ -0,0 +1 @@ +package gateway diff --git a/pkg/gateway/stream_grpcweb.go b/pkg/gateway/stream_grpcweb.go new file mode 100644 index 00000000..fa0ed3c2 --- /dev/null +++ b/pkg/gateway/stream_grpcweb.go @@ -0,0 +1 @@ +package gateway From c4d8bda76579c296c410ffc716d0a38aee50541b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 13 Jul 2024 20:03:06 +0800 Subject: [PATCH 23/41] fix: barry 2024-07-13 20:03:06 --- pkg/gateway/mux.go | 3 +++ servers/grpcs/server.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 27ca24d5..a0bae5ba 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -317,6 +317,9 @@ func (m *Mux) registerRouter(rule *methodWrapper) { if rule.meta != nil { m.opts.customOperationNames[rule.meta.Name] = rule } + + assert.Exit(m.routerTree.Add(http.MethodPost, rule.grpcFullMethod, rule.grpcFullMethod, + resolveBodyDesc(rule.grpcMethodPbDesc, "*", "*"))) } func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index c700b241..259435fc 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -370,9 +370,9 @@ func (s *serviceImpl) DixInject( httpServer.Group(apiPrefix1, httputil.StripPrefix(apiPrefix1, mux.Handler)) for _, m := range mux.GetRouteMethods() { log.Info(). - Str("method-name", m.Operation). + Str("operation", m.Operation). Str("http-method", m.Method). - Str("http-path", assert.Must1(url.JoinPath(apiPrefix1, m.Path))). + Str("http-path", "/"+strings.Trim(apiPrefix1, "/")+m.Path). Str("verb", m.Verb). Any("path-vars", m.Vars). Any("extras", m.Extras). From 9da823a260b4035256aeb2e0b59cf4f0d3fe0b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Thu, 18 Jul 2024 23:10:00 +0800 Subject: [PATCH 24/41] fix: barry 2024-07-18 23:10:00 --- core/logging/builder.go | 7 +++++++ go.mod | 6 +++--- go.sum | 8 ++++---- internal/example/grpc/main.go | 15 +++++++++++++++ servers/grpcs/server.go | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/core/logging/builder.go b/core/logging/builder.go index a1cf99f3..b0b3b61e 100644 --- a/core/logging/builder.go +++ b/core/logging/builder.go @@ -9,10 +9,17 @@ import ( "github.com/pubgo/funk/recovery" "github.com/pubgo/funk/result" "github.com/pubgo/funk/running" + "github.com/pubgo/funk/stack" "github.com/pubgo/lava/core/logging/logkey" "github.com/rs/zerolog" ) +func init() { + zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string { + return stack.Stack(pc).Short() + } +} + // New logger func New(cfg *Config) log.Logger { defer recovery.Exit() diff --git a/go.mod b/go.mod index 49e88b8e..a34d0e47 100644 --- a/go.mod +++ b/go.mod @@ -61,8 +61,9 @@ require ( github.com/libp2p/go-yamux/v4 v4.0.1 github.com/maragudk/gomponents v0.20.0 github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e - github.com/pubgo/dix v0.3.15 - github.com/pubgo/funk v0.5.45 + github.com/prometheus/common v0.48.0 + github.com/pubgo/dix v0.3.17 + github.com/pubgo/funk v0.5.48 github.com/rs/xid v1.5.0 github.com/rs/zerolog v1.33.0 github.com/samber/lo v1.44.0 @@ -173,7 +174,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/client_model v0.5.0 // indirect - github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect diff --git a/go.sum b/go.sum index d2f60c7b..389aff5c 100644 --- a/go.sum +++ b/go.sum @@ -474,10 +474,10 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/pubgo/dix v0.3.15 h1:DLjXfnyhcxT3skM1pZi60i/QgnUEg9nM6CI8wom7gVc= -github.com/pubgo/dix v0.3.15/go.mod h1:0j+i8YYn4vJnsJQCsyHXUGovR+Mgkh3uZPRhacw09us= -github.com/pubgo/funk v0.5.45 h1:9mfoi40ARbJWnjSGbGYXbBEHtwn4cbg8Ez0uYyoCaCg= -github.com/pubgo/funk v0.5.45/go.mod h1:Hm4oOYENrlr8A8nuH2YQWdx5jGg1fjAjaTvN2I28ts4= +github.com/pubgo/dix v0.3.17 h1:qWyShvxMcUgJes2l+QKimaorDg32Nh6joyckXADwUaI= +github.com/pubgo/dix v0.3.17/go.mod h1:J0PyuMm7mW6ZrN13l9xz0rtKbzliREFyvb7fuaGYyVw= +github.com/pubgo/funk v0.5.48 h1:ZWBv8Rg4PU2DaqpMYDOxeGNLg+sTnO2iPak9MVKMdug= +github.com/pubgo/funk v0.5.48/go.mod h1:Hm4oOYENrlr8A8nuH2YQWdx5jGg1fjAjaTvN2I28ts4= github.com/pubgo/opendoc v0.0.5 h1:aM6xkBQ0XMSq8OWytl5JhTMBUv8L+aYQFXd2z9eNkZE= github.com/pubgo/opendoc v0.0.5/go.mod h1:uO//pJZTJNFEKGuGWrv51/of0EoyxO1il4MuoC3Enp0= github.com/reugn/go-quartz v0.11.2 h1:+jc54Ji06n/D/endEPmc+CuG/Jc8466nda1oxtFRrks= diff --git a/internal/example/grpc/main.go b/internal/example/grpc/main.go index b3974ef1..642cf3f3 100644 --- a/internal/example/grpc/main.go +++ b/internal/example/grpc/main.go @@ -1,9 +1,24 @@ package main import ( + "context" + + "github.com/pubgo/funk/log" "github.com/pubgo/lava/internal/example/grpc/internal/bootstrap" ) func main() { + log.SetEnableChecker(func(ctx context.Context, lvl log.Level, nameOrMessage string, fields log.Map) bool { + if nameOrMessage == "eval type value" { + return false + } + + if nameOrMessage == "grpc-server" { + return false + } + + return true + }) + bootstrap.Main() } diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index 259435fc..47aec331 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -375,7 +375,7 @@ func (s *serviceImpl) DixInject( Str("http-path", "/"+strings.Trim(apiPrefix1, "/")+m.Path). Str("verb", m.Verb). Any("path-vars", m.Vars). - Any("extras", m.Extras). + Str("extras", fmt.Sprintf("%v", m.Extras)). Msg("grpc gateway router info") } From d433cf97cc4a424c22e839d0430442969dedd683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 19 Jul 2024 11:43:30 +0800 Subject: [PATCH 25/41] fix: barry 2024-07-19 11:43:30 --- core/debug/logdy/debug.go | 32 ++++++++++++++++++++++++++++++++ core/logging/builder.go | 12 ++++++++++-- go.mod | 11 ++++++++++- go.sum | 23 +++++++++++++++++++++-- internal/example/grpc/main.go | 1 + 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 core/debug/logdy/debug.go diff --git a/core/debug/logdy/debug.go b/core/debug/logdy/debug.go new file mode 100644 index 00000000..de268a5a --- /dev/null +++ b/core/debug/logdy/debug.go @@ -0,0 +1,32 @@ +package logdy + +import ( + "net/http" + + "github.com/gofiber/fiber/v2" + "github.com/logdyhq/logdy-core/logdy" + _ "github.com/logdyhq/logdy-core/logdy" + "github.com/pubgo/lava/core/debug" + "github.com/pubgo/lava/pkg/httputil" +) + +func init() { + mux := http.NewServeMux() + logdy.InitializeLogdy(logdy.Config{HttpPathPrefix: "/logs"}, mux) + + debug.Route("/logs", func(r fiber.Router) { + //r.Use(func(ctx *fiber.Ctx) error { + // path := string(ctx.Request().URI().Path()) + // fmt.Println(path) + // + // return ctx.Next() + //}) + + r.Get("/", func(ctx *fiber.Ctx) error { + return httputil.HTTPHandler(mux)(ctx) + }) + r.Get("/*", func(ctx *fiber.Ctx) error { + return httputil.HTTPHandler(mux)(ctx) + }) + }) +} diff --git a/core/logging/builder.go b/core/logging/builder.go index b0b3b61e..503938f5 100644 --- a/core/logging/builder.go +++ b/core/logging/builder.go @@ -1,10 +1,13 @@ package logging import ( - "fmt" "os" "time" + "github.com/logdyhq/logdy-core/http" + "github.com/logdyhq/logdy-core/models" + "github.com/logdyhq/logdy-core/modes" + "github.com/pubgo/funk/convert" "github.com/pubgo/funk/log" "github.com/pubgo/funk/recovery" "github.com/pubgo/funk/result" @@ -67,7 +70,12 @@ type writer struct { func (w writer) Write(p []byte) (n int, err error) { n, err = w.ConsoleWriter.Write(p) if err != nil { - fmt.Println("invalid json: ", string(p)) + log.Err(err).Str("raw_json", string(p)).Msg("failed to decode invalid json") + return + } + + if http.Ch != nil { + go modes.ProduceMessageString(http.Ch, convert.BtoS(p), models.MessageTypeStdout, &models.MessageOrigin{}) } return } diff --git a/go.mod b/go.mod index a34d0e47..f5add905 100644 --- a/go.mod +++ b/go.mod @@ -55,10 +55,11 @@ require ( github.com/gofiber/websocket/v2 v2.2.1 github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 github.com/google/uuid v1.6.0 - github.com/gorilla/websocket v1.5.0 + github.com/gorilla/websocket v1.5.1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 github.com/libp2p/go-yamux/v4 v4.0.1 + github.com/logdyhq/logdy-core v0.13.0 github.com/maragudk/gomponents v0.20.0 github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e github.com/prometheus/common v0.48.0 @@ -96,15 +97,18 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Microsoft/hcsshim v0.11.4 // indirect + github.com/VividCortex/ewma v1.2.0 // indirect github.com/a8m/envsubst v1.3.0 // indirect github.com/agext/levenshtein v1.2.1 // indirect github.com/alecthomas/repr v0.2.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/brianvoe/gofakeit/v6 v6.28.0 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cheggaaa/pb/v3 v3.1.5 // indirect github.com/containerd/containerd v1.7.12 // indirect github.com/containerd/log v0.1.0 // indirect github.com/cpuguy83/dockercfg v0.3.1 // indirect @@ -113,8 +117,10 @@ require ( github.com/docker/docker v25.0.5+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect + github.com/fatih/color v1.15.0 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/getkin/kin-openapi v0.124.0 // indirect github.com/go-logr/logr v1.4.1 // indirect @@ -167,6 +173,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/morikuni/aec v1.0.0 // indirect + github.com/nxadm/tail v1.4.11 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect @@ -183,6 +190,7 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/twmb/murmur3 v1.1.5 // indirect + github.com/valyala/fastjson v1.6.4 // indirect github.com/valyala/tcplisten v1.0.0 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect @@ -195,6 +203,7 @@ require ( golang.org/x/text v0.16.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gorm.io/datatypes v1.0.7 // indirect gorm.io/hints v1.1.0 // indirect gorm.io/plugin/dbresolver v1.3.0 // indirect diff --git a/go.sum b/go.sum index 389aff5c..66b7c6cf 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8= github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w= +github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= +github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/a8m/envsubst v1.3.0 h1:GmXKmVssap0YtlU3E230W98RWtWCyIZzjtf1apWWyAg= github.com/a8m/envsubst v1.3.0/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= @@ -50,6 +52,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/brianvoe/gofakeit/v6 v6.28.0 h1:Xib46XXuQfmlLS2EXRuJpqcw8St6qSZz75OUo0tgAW4= +github.com/brianvoe/gofakeit/v6 v6.28.0/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= github.com/cactus/go-statsd-client/v5 v5.0.0/go.mod h1:COEvJ1E+/E2L4q6QE5CkjWPi4eeDw9maJBMIuMPBZbY= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -61,6 +65,8 @@ github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91 github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cheggaaa/pb/v3 v3.1.5 h1:QuuUzeM2WsAqG2gMqtzaWithDJv0i+i6UlnwSCI4QLk= +github.com/cheggaaa/pb/v3 v3.1.5/go.mod h1:CrxkeghYTXi1lQBEI7jSn+3svI3cuc19haAj6jM60XI= github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= @@ -118,12 +124,16 @@ github.com/fasthttp/router v1.5.0 h1:3Qbbo27HAPzwbpRzgiV5V9+2faPkPt3eNuRaDV6LYDA github.com/fasthttp/router v1.5.0/go.mod h1:FddcKNXFZg1imHcy+uKB0oo/o6yE9zD3wNguqlhWDak= github.com/fasthttp/websocket v1.5.8 h1:k5DpirKkftIF/w1R8ZzjSgARJrs54Je9YJK37DL/Ah8= github.com/fasthttp/websocket v1.5.8/go.mod h1:d08g8WaT6nnyvg9uMm8K9zMYyDjfKyj3170AtPRuVU0= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/felixge/fgprof v0.9.4 h1:ocDNwMFlnA0NU0zSB3I52xkO4sFXk80VK9lXjLClu88= github.com/felixge/fgprof v0.9.4/go.mod h1:yKl+ERSa++RYOs32d8K6WEXCB4uXdLls4ZaZPpayhMM= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fullstorydev/grpchan v1.1.1 h1:heQqIJlAv5Cnks9a70GRL2EJke6QQoUB25VGR6TZQas= github.com/fullstorydev/grpchan v1.1.1/go.mod h1:f4HpiV8V6htfY/K44GWV1ESQzHBTq7DinhzqQ95lpgc= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= @@ -228,8 +238,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/grandcat/zeroconf v1.0.0 h1:uHhahLBKqwWBV6WZUDAT71044vwOTL+McW0mBJvo6kE= github.com/grandcat/zeroconf v1.0.0/go.mod h1:lTKmG1zh86XyCoUeIHSA4FJMBwCJiQmGfcP2PdzytEs= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= @@ -364,6 +374,8 @@ github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOS github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-yamux/v4 v4.0.1 h1:FfDR4S1wj6Bw2Pqbc8Uz7pCxeRBPbwsBbEdfwiCypkQ= github.com/libp2p/go-yamux/v4 v4.0.1/go.mod h1:NWjl8ZTLOGlozrXSOZ/HlfG++39iKNnM5wwmtQP1YB4= +github.com/logdyhq/logdy-core v0.13.0 h1:56jvu7drwpEEp5c8pIkH5eqJuZ/aWmm1mtYI2tgRqqQ= +github.com/logdyhq/logdy-core v0.13.0/go.mod h1:dBD8UCyE4Zk0r86SxbiTS1MUN+33G9vGc5fM8jSm+TU= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= @@ -428,6 +440,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= +github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -559,6 +573,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ= +github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= +github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= @@ -728,6 +744,7 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -816,6 +833,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/validator.v2 v2.0.0-20200605151824-2b28d334fa05/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/example/grpc/main.go b/internal/example/grpc/main.go index 642cf3f3..b55aab11 100644 --- a/internal/example/grpc/main.go +++ b/internal/example/grpc/main.go @@ -4,6 +4,7 @@ import ( "context" "github.com/pubgo/funk/log" + _ "github.com/pubgo/lava/core/debug/logdy" "github.com/pubgo/lava/internal/example/grpc/internal/bootstrap" ) From 9da71fd2d78f369155703ac80947a3762f4fbc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Tue, 23 Jul 2024 15:54:52 +0800 Subject: [PATCH 26/41] fix: barry 2024-07-23 15:54:52 --- internal/example/grpc/main.go | 14 +-- .../grpc/pkg/proto/gidpb/id.errors.pb.go | 2 +- .../example/grpc/pkg/proto/gidpb/id.pb.go | 98 ++++++++++--------- .../grpc/pkg/proto/gidpb/id_grpc.pb.go | 2 +- internal/example/grpc/proto/gid/id.proto | 5 +- internal/example/grpc/protobuf.yaml | 4 +- pkg/proto/errcodepb/api.pb.go | 8 +- pkg/proto/errcodepb/api_grpc.pb.go | 2 +- pkg/proto/lavapbv1/event.pb.go | 6 +- pkg/proto/lavapbv1/form_file.pb.go | 8 +- pkg/proto/lavapbv1/rpc.pb.go | 79 +++++++++------ pkg/proto/lavapbv1/service.pb.go | 8 +- pkg/proto/metadatapb/metadata.pb.go | 14 +-- pkg/proto/metadatapb/metadata_grpc.pb.go | 2 +- proto/lava/rpc.proto | 1 + protobuf.yaml | 2 +- servers/grpcs/server.go | 1 + 17 files changed, 140 insertions(+), 116 deletions(-) diff --git a/internal/example/grpc/main.go b/internal/example/grpc/main.go index b55aab11..4a12d761 100644 --- a/internal/example/grpc/main.go +++ b/internal/example/grpc/main.go @@ -10,13 +10,13 @@ import ( func main() { log.SetEnableChecker(func(ctx context.Context, lvl log.Level, nameOrMessage string, fields log.Map) bool { - if nameOrMessage == "eval type value" { - return false - } - - if nameOrMessage == "grpc-server" { - return false - } + //if nameOrMessage == "eval type value" { + // return false + //} + // + //if nameOrMessage == "grpc-server" { + // return false + //} return true }) diff --git a/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go index f49e957f..ecb95bb7 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.errors.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-errors. DO NOT EDIT. // versions: // - protoc-gen-go-errors v0.0.5 -// - protoc v5.27.0 +// - protoc v5.27.1 // source: gid/id.proto package gidpb diff --git a/internal/example/grpc/pkg/proto/gidpb/id.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.pb.go index 0f9ab1c0..22891abd 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: gid/id.proto package gidpb @@ -569,48 +569,50 @@ var file_gid_id_proto_rawDesc = []byte{ 0x00, 0x12, 0x08, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x73, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x67, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x68, 0x6f, 0x72, - 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xff, 0x04, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x5f, 0x0a, 0x08, + 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0x9d, 0x05, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x7d, 0x0a, 0x08, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x26, 0xa2, 0xea, 0x30, 0x08, 0x0a, 0x06, 0x69, 0x64, 0x2e, - 0x67, 0x65, 0x6e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x76, - 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x4c, 0x0a, - 0x0a, 0x54, 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x67, 0x69, - 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, - 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, - 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, 0x0a, 0x05, 0x54, - 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, - 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x82, 0xd3, 0xe4, - 0x93, 0x02, 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, - 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, - 0x64, 0x7d, 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, - 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, - 0x1a, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, - 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, - 0x6f, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x44, 0xa2, 0xea, 0x30, 0x26, 0x0a, 0x06, 0x69, 0x64, 0x2e, + 0x67, 0x65, 0x6e, 0x1a, 0x10, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x12, + 0x04, 0x74, 0x72, 0x75, 0x65, 0x1a, 0x0a, 0x0a, 0x03, 0x73, 0x73, 0x73, 0x12, 0x03, 0x73, 0x73, + 0x73, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, + 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x4c, 0x0a, 0x0a, 0x54, + 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, + 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, + 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, + 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, 0x0a, 0x05, 0x54, 0x79, 0x70, + 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, + 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, + 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, + 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x1a, 0x1d, + 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, + 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x6f, 0x0a, + 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, + 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0xba, 0x47, 0x27, 0x0a, 0x0d, + 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x0a, 0x0e, 0x63, + 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x31, 0x12, 0x06, 0xe8, + 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x3a, 0x03, 0x6d, 0x73, 0x67, + 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, 0x01, 0x30, 0x01, 0x12, 0x31, + 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0xba, 0x47, 0x27, - 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x0a, - 0x0e, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x31, 0x12, - 0x06, 0xe8, 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x3a, 0x03, 0x6d, - 0x73, 0x67, 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, 0x01, 0x30, 0x01, - 0x12, 0x31, 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, - 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, - 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x6f, 0x77, - 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, 0x70, 0x6c, 0x6f, - 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, - 0x6f, 0x64, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, 0x66, 0x69, 0x6c, - 0x65, 0x22, 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, 0x6c, 0x65, 0x6e, - 0x61, 0x6d, 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, - 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x67, 0x69, 0x64, - 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, + 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, + 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, + 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, + 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, + 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, + 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, + 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x67, 0x69, 0x64, 0x70, 0x62, + 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -627,7 +629,7 @@ func file_gid_id_proto_rawDescGZIP() []byte { var file_gid_id_proto_enumTypes = make([]protoimpl.EnumInfo, 2) var file_gid_id_proto_msgTypes = make([]protoimpl.MessageInfo, 7) -var file_gid_id_proto_goTypes = []interface{}{ +var file_gid_id_proto_goTypes = []any{ (SrvCode)(0), // 0: gid.SrvCode (GenType)(0), // 1: gid.GenType (*GenerateResponse)(nil), // 2: gid.GenerateResponse @@ -670,7 +672,7 @@ func file_gid_id_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_gid_id_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*GenerateResponse); i { case 0: return &v.state @@ -682,7 +684,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*UploadFileRequest); i { case 0: return &v.state @@ -694,7 +696,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*ChatMessage); i { case 0: return &v.state @@ -706,7 +708,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*Message); i { case 0: return &v.state @@ -718,7 +720,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*GenerateRequest); i { case 0: return &v.state @@ -730,7 +732,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*TypesRequest); i { case 0: return &v.state @@ -742,7 +744,7 @@ func file_gid_id_proto_init() { return nil } } - file_gid_id_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_gid_id_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*TypesResponse); i { case 0: return &v.state diff --git a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go index c1569d91..345ca93c 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v5.27.0 +// - protoc v5.27.1 // source: gid/id.proto package gidpb diff --git a/internal/example/grpc/proto/gid/id.proto b/internal/example/grpc/proto/gid/id.proto index 826affd9..482d67fa 100644 --- a/internal/example/grpc/proto/gid/id.proto +++ b/internal/example/grpc/proto/gid/id.proto @@ -24,7 +24,10 @@ service Id { // Generate 生成ID rpc Generate (GenerateRequest) returns (GenerateResponse) { - option (lava.rpc.options) = {name: "id.gen"}; + option (lava.rpc.options) = { + name: "id.gen", + tags: [{key: "internal",value: "true"},{key: "hello",value: "world"}] + }; option (google.api.http) = { post: "/v1/id/generate" body: "*" diff --git a/internal/example/grpc/protobuf.yaml b/internal/example/grpc/protobuf.yaml index 6a624ee1..8c729ffe 100644 --- a/internal/example/grpc/protobuf.yaml +++ b/internal/example/grpc/protobuf.yaml @@ -1,4 +1,4 @@ -checksum: ea83f2fc3aa1588147f4bdaf251b3cd86fde7ca8 +checksum: 1aee5ba9edd17a44e0dc80045c51f3b1dbbc99a6 vendor: ../../../.proto root: - proto @@ -30,7 +30,7 @@ deps: - name: errorpb url: github.com/pubgo/funk path: /proto/errorpb - version: v0.5.45 + version: v0.5.48 plugins: - name: go out: pkg/proto diff --git a/pkg/proto/errcodepb/api.pb.go b/pkg/proto/errcodepb/api.pb.go index 342aa59b..11b7e661 100644 --- a/pkg/proto/errcodepb/api.pb.go +++ b/pkg/proto/errcodepb/api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/services/errcode/api.proto package errcodepb @@ -110,7 +110,7 @@ func file_proto_lava_services_errcode_api_proto_rawDescGZIP() []byte { } var file_proto_lava_services_errcode_api_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proto_lava_services_errcode_api_proto_goTypes = []interface{}{ +var file_proto_lava_services_errcode_api_proto_goTypes = []any{ (*ErrCodes)(nil), // 0: lava.service.ErrCodes (*errorpb.ErrCode)(nil), // 1: errors.ErrCode (*emptypb.Empty)(nil), // 2: google.protobuf.Empty @@ -132,7 +132,7 @@ func file_proto_lava_services_errcode_api_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_proto_lava_services_errcode_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_errcode_api_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ErrCodes); i { case 0: return &v.state diff --git a/pkg/proto/errcodepb/api_grpc.pb.go b/pkg/proto/errcodepb/api_grpc.pb.go index 840d4ea9..3d9adbb6 100644 --- a/pkg/proto/errcodepb/api_grpc.pb.go +++ b/pkg/proto/errcodepb/api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v5.27.0 +// - protoc v5.27.1 // source: proto/lava/services/errcode/api.proto package errcodepb diff --git a/pkg/proto/lavapbv1/event.pb.go b/pkg/proto/lavapbv1/event.pb.go index 46d5eec6..3eb4dbc9 100644 --- a/pkg/proto/lavapbv1/event.pb.go +++ b/pkg/proto/lavapbv1/event.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/event.proto package lavapbv1 @@ -100,7 +100,7 @@ func file_proto_lava_event_proto_rawDescGZIP() []byte { } var file_proto_lava_event_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_proto_lava_event_proto_goTypes = []interface{}{ +var file_proto_lava_event_proto_goTypes = []any{ (EventType)(0), // 0: lava.v1.EventType } var file_proto_lava_event_proto_depIdxs = []int32{ diff --git a/pkg/proto/lavapbv1/form_file.pb.go b/pkg/proto/lavapbv1/form_file.pb.go index 1c64b249..76992f37 100644 --- a/pkg/proto/lavapbv1/form_file.pb.go +++ b/pkg/proto/lavapbv1/form_file.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/form_file.proto package lavapbv1 @@ -123,7 +123,7 @@ func file_proto_lava_form_file_proto_rawDescGZIP() []byte { } var file_proto_lava_form_file_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proto_lava_form_file_proto_goTypes = []interface{}{ +var file_proto_lava_form_file_proto_goTypes = []any{ (*FormFile)(nil), // 0: lava.v1.FormFile } var file_proto_lava_form_file_proto_depIdxs = []int32{ @@ -140,7 +140,7 @@ func file_proto_lava_form_file_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_proto_lava_form_file_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_form_file_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*FormFile); i { case 0: return &v.state diff --git a/pkg/proto/lavapbv1/rpc.pb.go b/pkg/proto/lavapbv1/rpc.pb.go index aaa6b15a..d9535b47 100644 --- a/pkg/proto/lavapbv1/rpc.pb.go +++ b/pkg/proto/lavapbv1/rpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/rpc.proto package lavapbv1 @@ -26,8 +26,9 @@ type RpcMeta struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Version *string `protobuf:"bytes,2,opt,name=version,proto3,oneof" json:"version,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Version *string `protobuf:"bytes,2,opt,name=version,proto3,oneof" json:"version,omitempty"` + Tags map[string]string `protobuf:"bytes,3,rep,name=tags,proto3" json:"tags,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *RpcMeta) Reset() { @@ -76,6 +77,13 @@ func (x *RpcMeta) GetVersion() string { return "" } +func (x *RpcMeta) GetTags() map[string]string { + if x != nil { + return x.Tags + } + return nil +} + var file_proto_lava_rpc_proto_extTypes = []protoimpl.ExtensionInfo{ { ExtendedType: (*descriptorpb.MethodOptions)(nil), @@ -100,20 +108,27 @@ var file_proto_lava_rpc_proto_rawDesc = []byte{ 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x48, 0x0a, 0x07, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, 0x01, 0x01, - 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x4d, 0x0a, 0x07, - 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x11, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, - 0x74, 0x61, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x33, 0x5a, 0x31, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, - 0x6c, 0x61, 0x76, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, - 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x3b, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x6f, 0x22, 0xb2, 0x01, 0x0a, 0x07, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x88, 0x01, + 0x01, 0x12, 0x2f, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x1b, 0x2e, 0x6c, 0x61, 0x76, 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, + 0x74, 0x61, 0x2e, 0x54, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x74, 0x61, + 0x67, 0x73, 0x1a, 0x37, 0x0a, 0x09, 0x54, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x4d, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0xa4, 0x8d, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6c, 0x61, 0x76, + 0x61, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x52, 0x70, 0x63, 0x4d, 0x65, 0x74, 0x61, 0x52, 0x07, 0x6f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x75, 0x62, 0x67, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, + 0x76, 0x31, 0x3b, 0x6c, 0x61, 0x76, 0x61, 0x70, 0x62, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -128,19 +143,21 @@ func file_proto_lava_rpc_proto_rawDescGZIP() []byte { return file_proto_lava_rpc_proto_rawDescData } -var file_proto_lava_rpc_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proto_lava_rpc_proto_goTypes = []interface{}{ +var file_proto_lava_rpc_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_lava_rpc_proto_goTypes = []any{ (*RpcMeta)(nil), // 0: lava.rpc.RpcMeta - (*descriptorpb.MethodOptions)(nil), // 1: google.protobuf.MethodOptions + nil, // 1: lava.rpc.RpcMeta.TagsEntry + (*descriptorpb.MethodOptions)(nil), // 2: google.protobuf.MethodOptions } var file_proto_lava_rpc_proto_depIdxs = []int32{ - 1, // 0: lava.rpc.options:extendee -> google.protobuf.MethodOptions - 0, // 1: lava.rpc.options:type_name -> lava.rpc.RpcMeta - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 1, // [1:2] is the sub-list for extension type_name - 0, // [0:1] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 1, // 0: lava.rpc.RpcMeta.tags:type_name -> lava.rpc.RpcMeta.TagsEntry + 2, // 1: lava.rpc.options:extendee -> google.protobuf.MethodOptions + 0, // 2: lava.rpc.options:type_name -> lava.rpc.RpcMeta + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 2, // [2:3] is the sub-list for extension type_name + 1, // [1:2] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_proto_lava_rpc_proto_init() } @@ -149,7 +166,7 @@ func file_proto_lava_rpc_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_proto_lava_rpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_rpc_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*RpcMeta); i { case 0: return &v.state @@ -162,14 +179,14 @@ func file_proto_lava_rpc_proto_init() { } } } - file_proto_lava_rpc_proto_msgTypes[0].OneofWrappers = []interface{}{} + file_proto_lava_rpc_proto_msgTypes[0].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_lava_rpc_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 1, NumServices: 0, }, diff --git a/pkg/proto/lavapbv1/service.pb.go b/pkg/proto/lavapbv1/service.pb.go index 9d0f22e1..d56a676f 100644 --- a/pkg/proto/lavapbv1/service.pb.go +++ b/pkg/proto/lavapbv1/service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/service.proto package lavapbv1 @@ -131,7 +131,7 @@ func file_proto_lava_service_proto_rawDescGZIP() []byte { } var file_proto_lava_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_proto_lava_service_proto_goTypes = []interface{}{ +var file_proto_lava_service_proto_goTypes = []any{ (*ServiceInfo)(nil), // 0: lava.v1.ServiceInfo } var file_proto_lava_service_proto_depIdxs = []int32{ @@ -148,7 +148,7 @@ func file_proto_lava_service_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_proto_lava_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_service_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ServiceInfo); i { case 0: return &v.state diff --git a/pkg/proto/metadatapb/metadata.pb.go b/pkg/proto/metadatapb/metadata.pb.go index d3c71872..16f78bff 100644 --- a/pkg/proto/metadatapb/metadata.pb.go +++ b/pkg/proto/metadatapb/metadata.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.27.0 +// protoc-gen-go v1.34.2 +// protoc v5.27.1 // source: proto/lava/services/metadata/metadata.proto package metadatapb @@ -270,7 +270,7 @@ func file_proto_lava_services_metadata_metadata_proto_rawDescGZIP() []byte { } var file_proto_lava_services_metadata_metadata_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_proto_lava_services_metadata_metadata_proto_goTypes = []interface{}{ +var file_proto_lava_services_metadata_metadata_proto_goTypes = []any{ (*ListServicesRequest)(nil), // 0: lava.service.ListServicesRequest (*ListServicesReply)(nil), // 1: lava.service.ListServicesReply (*GetServiceDescRequest)(nil), // 2: lava.service.GetServiceDescRequest @@ -296,7 +296,7 @@ func file_proto_lava_services_metadata_metadata_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_proto_lava_services_metadata_metadata_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ListServicesRequest); i { case 0: return &v.state @@ -308,7 +308,7 @@ func file_proto_lava_services_metadata_metadata_proto_init() { return nil } } - file_proto_lava_services_metadata_metadata_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*ListServicesReply); i { case 0: return &v.state @@ -320,7 +320,7 @@ func file_proto_lava_services_metadata_metadata_proto_init() { return nil } } - file_proto_lava_services_metadata_metadata_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*GetServiceDescRequest); i { case 0: return &v.state @@ -332,7 +332,7 @@ func file_proto_lava_services_metadata_metadata_proto_init() { return nil } } - file_proto_lava_services_metadata_metadata_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_proto_lava_services_metadata_metadata_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*GetServiceDescReply); i { case 0: return &v.state diff --git a/pkg/proto/metadatapb/metadata_grpc.pb.go b/pkg/proto/metadatapb/metadata_grpc.pb.go index 09554ac6..70975e6a 100644 --- a/pkg/proto/metadatapb/metadata_grpc.pb.go +++ b/pkg/proto/metadatapb/metadata_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v5.27.0 +// - protoc v5.27.1 // source: proto/lava/services/metadata/metadata.proto package metadatapb diff --git a/proto/lava/rpc.proto b/proto/lava/rpc.proto index 5a5420bb..0bec0c71 100644 --- a/proto/lava/rpc.proto +++ b/proto/lava/rpc.proto @@ -9,6 +9,7 @@ option go_package = "github.com/pubgo/lava/pkg/proto/lavapbv1;lavapbv1"; message RpcMeta { string name = 1; optional string version = 2; + map tags = 3; } extend google.protobuf.MethodOptions { diff --git a/protobuf.yaml b/protobuf.yaml index 90659ffd..3b49a2ce 100644 --- a/protobuf.yaml +++ b/protobuf.yaml @@ -16,7 +16,7 @@ deps: - name: errorpb url: github.com/pubgo/funk path: /proto/errorpb - version: v0.5.45 + version: v0.5.48 plugins: - name: go - name: go-errors diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index 47aec331..40708ff8 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -371,6 +371,7 @@ func (s *serviceImpl) DixInject( for _, m := range mux.GetRouteMethods() { log.Info(). Str("operation", m.Operation). + Any("rpc-meta", mux.GetOperation(m.Operation).Meta). Str("http-method", m.Method). Str("http-path", "/"+strings.Trim(apiPrefix1, "/")+m.Path). Str("verb", m.Verb). From f6e2e0b3b328458abc5d793a92c17605f1197188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Wed, 24 Jul 2024 13:39:43 +0800 Subject: [PATCH 27/41] fix: barry 2024-07-24 13:39:43 --- core/flags/default.go | 13 +- core/logging/builder.go | 2 +- go.mod | 1 + go.sum | 17 ++ internal/example/grpc/Makefile | 5 +- internal/example/grpc/configs/config.yaml | 2 + internal/example/grpc/docs/api.http | 8 + .../example/grpc/internal/bootstrap/boot.go | 43 ++-- .../handlers/gid_handler/handler_proxy.go | 43 ++++ .../gid_handler/handler_proxy_server.go | 34 +++ internal/example/grpc/main_proxy.go | 25 ++ internal/example/grpc/openapi.yaml | 33 ++- .../example/grpc/pkg/proto/gidpb/id.pb.go | 89 ++++---- .../example/grpc/pkg/proto/gidpb/proxy.pb.go | 213 ++++++++++++++++++ .../grpc/pkg/proto/gidpb/proxy_grpc.pb.go | 107 +++++++++ internal/example/grpc/proto/gid/proxy.proto | 24 ++ lava/router.go | 5 + pkg/gateway/_doc.go | 4 +- pkg/gateway/aaa.go | 5 + pkg/gateway/mux.go | 57 +++-- pkg/gateway/stream_http.go | 2 +- pkg/gateway/stream_proxy.go | 145 ++++++++++-- pkg/gateway/wrapper.go | 49 +++- servers/grpcs/server.go | 31 ++- 24 files changed, 840 insertions(+), 117 deletions(-) create mode 100644 internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go create mode 100644 internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go create mode 100644 internal/example/grpc/main_proxy.go create mode 100644 internal/example/grpc/pkg/proto/gidpb/proxy.pb.go create mode 100644 internal/example/grpc/pkg/proto/gidpb/proxy_grpc.pb.go create mode 100644 internal/example/grpc/proto/gid/proxy.proto diff --git a/core/flags/default.go b/core/flags/default.go index caeaf0f1..293e5544 100644 --- a/core/flags/default.go +++ b/core/flags/default.go @@ -10,17 +10,24 @@ import ( ) func init() { + const httpPort = "server_http_port" + const grpcPort = "server_grpc_port" + const conf = "config_path" + env.GetIntVal(&running.HttpPort, httpPort) + env.GetIntVal(&running.GrpcPort, grpcPort) + Register(&cli.IntFlag{ Name: "http-port", Usage: "service http port", Persistent: true, Value: int64(running.HttpPort), - Sources: cli.EnvVars(env.Key("server_http_port")), + Sources: cli.EnvVars(env.Key(httpPort)), Action: func(ctx context.Context, command *cli.Command, i int64) error { running.HttpPort = int(i) return nil }, }) + Register(&cli.IntFlag{ Name: "grpc-port", Usage: "service grpc port", @@ -32,6 +39,7 @@ func init() { return nil }, }) + Register(&cli.BoolFlag{ Name: "debug", Usage: "enable debug mode", @@ -40,13 +48,14 @@ func init() { Destination: &running.IsDebug, Sources: cli.EnvVars(env.Key("debug"), env.Key("enable_debug")), }) + Register(&cli.StringFlag{ Name: "config", Aliases: []string{"c"}, Usage: "config path", Value: config.GetConfigPath(), Persistent: true, - Sources: cli.EnvVars(env.Key("config_path")), + Sources: cli.EnvVars(env.Key(conf)), Action: func(ctx context.Context, command *cli.Command, s string) error { config.SetConfigPath(s) return nil diff --git a/core/logging/builder.go b/core/logging/builder.go index 503938f5..fff36b4a 100644 --- a/core/logging/builder.go +++ b/core/logging/builder.go @@ -75,7 +75,7 @@ func (w writer) Write(p []byte) (n int, err error) { } if http.Ch != nil { - go modes.ProduceMessageString(http.Ch, convert.BtoS(p), models.MessageTypeStdout, &models.MessageOrigin{}) + go modes.ProduceMessageString(http.Ch, convert.BtoS(p[:n]), models.MessageTypeStdout, &models.MessageOrigin{}) } return } diff --git a/go.mod b/go.mod index f5add905..8407cfbd 100644 --- a/go.mod +++ b/go.mod @@ -62,6 +62,7 @@ require ( github.com/logdyhq/logdy-core v0.13.0 github.com/maragudk/gomponents v0.20.0 github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e + github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 github.com/prometheus/common v0.48.0 github.com/pubgo/dix v0.3.17 github.com/pubgo/funk v0.5.48 diff --git a/go.sum b/go.sum index 66b7c6cf..6d0a79dd 100644 --- a/go.sum +++ b/go.sum @@ -114,6 +114,7 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.12.0 h1:4X+VP1GHd1Mhj6IB5mMeGbLCleqxjletLK6K0rbxyZI= github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0= @@ -216,6 +217,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 h1:0VpGH+cDhbDtdcweoyCVsF3fhN8kejK6rFe/2FFX2nU= @@ -440,6 +443,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 h1:62uLwA3l2JMH84liO4ZhnjTH5PjFyCYxbHLgXPaJMtI= +github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= @@ -668,6 +673,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -693,6 +699,8 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -732,8 +740,12 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -779,8 +791,10 @@ golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= @@ -798,6 +812,7 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20210401141331-865547bb08e2/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e h1:SkdGTrROJl2jRGT/Fxv5QUf9jtdKCQh4KQJXbXVLAi0= @@ -809,6 +824,7 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= @@ -882,3 +898,4 @@ gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= diff --git a/internal/example/grpc/Makefile b/internal/example/grpc/Makefile index d994ac80..46daff13 100644 --- a/internal/example/grpc/Makefile +++ b/internal/example/grpc/Makefile @@ -12,8 +12,11 @@ LDFLAGS=-ldflags " \ -X '${Base}/version.project=${Project}' \ " +run_proxy: + enable_debug=true go run ${LDFLAGS} -v main_proxy.go grpc + run: - enable_debug=true go run ${LDFLAGS} -v main.go grpc + enable_debug=true server_grpc_port=50052 server_http_port=8081 go run ${LDFLAGS} -v main.go grpc .PHONY: build build-gid: diff --git a/internal/example/grpc/configs/config.yaml b/internal/example/grpc/configs/config.yaml index ca7aba71..c5a0b5ca 100644 --- a/internal/example/grpc/configs/config.yaml +++ b/internal/example/grpc/configs/config.yaml @@ -29,6 +29,8 @@ grpc_server: enable_print_routes: true enable_cors: true ws_read_limit: 10 +# http_port: 8081 +# grpc_port: 50052 #task: # http_port: 8081 diff --git a/internal/example/grpc/docs/api.http b/internal/example/grpc/docs/api.http index fff8fecc..76d63e05 100644 --- a/internal/example/grpc/docs/api.http +++ b/internal/example/grpc/docs/api.http @@ -9,3 +9,11 @@ Content-Type: application/json { "hello": "content" } + +### proxy +POST http://localhost:8081/gid/gw/v1/id/echo +Content-Type: application/json + +{ + "hello": "hello" +} diff --git a/internal/example/grpc/internal/bootstrap/boot.go b/internal/example/grpc/internal/bootstrap/boot.go index 4b678314..b65369ec 100644 --- a/internal/example/grpc/internal/bootstrap/boot.go +++ b/internal/example/grpc/internal/bootstrap/boot.go @@ -1,16 +1,12 @@ package bootstrap import ( - "context" - "fmt" - "github.com/pubgo/funk/config" "github.com/pubgo/funk/recovery" "github.com/pubgo/lava/cmds/app" "github.com/pubgo/lava/internal/example/grpc/internal/handlers/gid_handler" "github.com/pubgo/lava/internal/example/grpc/internal/services/gid_client" "github.com/pubgo/lava/internal/example/grpc/taskcmd" - "github.com/pubgo/lava/lava" ) func Main() { @@ -24,18 +20,33 @@ func Main() { di.Provide(gid_handler.NewHttp111) di.Provide(gid_client.New) di.Provide(taskcmd.New) - di.Provide(func() lava.Middleware { - return lava.MiddlewareWrap{ - Name: "t", - Next: func(next lava.HandlerFunc) lava.HandlerFunc { - return func(ctx context.Context, req lava.Request) (lava.Response, error) { - fmt.Println("endpoint", req.Endpoint()) - fmt.Println("header", req.Header().String()) - return next(ctx, req) - } - }, - } - }) + //di.Provide(func() lava.Middleware { + // return lava.MiddlewareWrap{ + // Name: "t", + // Next: func(next lava.HandlerFunc) lava.HandlerFunc { + // return func(ctx context.Context, req lava.Request) (lava.Response, error) { + // fmt.Println("endpoint", req.Endpoint()) + // fmt.Println("header", req.Header().String()) + // return next(ctx, req) + // } + // }, + // } + //}) + + // proxy + di.Provide(gid_handler.NewIdProxy) + + app.Run(di) +} + +func MainProxy() { + defer recovery.Exit() + + di := app.NewBuilder() + di.Provide(config.Load[Config]) + + // proxy + di.Provide(gid_handler.NewIdProxyServer) app.Run(di) } diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go new file mode 100644 index 00000000..782efe40 --- /dev/null +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go @@ -0,0 +1,43 @@ +package gid_handler + +import ( + "context" + "fmt" + "google.golang.org/grpc/credentials/insecure" + + "github.com/pubgo/funk/assert" + "github.com/pubgo/lava/internal/example/grpc/pkg/proto/gidpb" + "github.com/pubgo/lava/lava" + "google.golang.org/grpc" +) + +var ( + _ lava.GrpcProxy = (*IdProxy)(nil) +) + +func NewIdProxy() lava.GrpcProxy { + return &IdProxy{} +} + +type IdProxy struct { +} + +func (i IdProxy) Middlewares() []lava.Middleware { + return lava.Middlewares{ + lava.MiddlewareWrap{ + Next: func(next lava.HandlerFunc) lava.HandlerFunc { + return func(ctx context.Context, req lava.Request) (lava.Response, error) { + fmt.Println("proxy-header", req.Header().String()) + return next(ctx, req) + } + }, + Name: "proxy", + }, + } +} + +func (i IdProxy) ServiceDesc() *grpc.ServiceDesc { return &gidpb.IdProxy_ServiceDesc } + +func (i IdProxy) Proxy() grpc.ClientConnInterface { + return assert.Must1(grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))) +} diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go new file mode 100644 index 00000000..2b29c7a4 --- /dev/null +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go @@ -0,0 +1,34 @@ +package gid_handler + +import ( + "context" + "fmt" + + "github.com/pubgo/lava/internal/example/grpc/pkg/proto/gidpb" + "github.com/pubgo/lava/lava" + "google.golang.org/grpc" +) + +var ( + _ lava.GrpcRouter = (*IdProxyServer)(nil) + _ gidpb.IdProxyServer = (*IdProxyServer)(nil) +) + +func NewIdProxyServer() lava.GrpcRouter { + return &IdProxyServer{} +} + +type IdProxyServer struct { +} + +func (i IdProxyServer) Echo(ctx context.Context, req *gidpb.EchoReq) (*gidpb.EchoRsp, error) { + fmt.Println("get echo request", req.String()) + return &gidpb.EchoRsp{Hello: req.Hello}, nil +} + +func (i IdProxyServer) Middlewares() []lava.Middleware { + //TODO implement me + return nil +} + +func (i IdProxyServer) ServiceDesc() *grpc.ServiceDesc { return &gidpb.IdProxy_ServiceDesc } diff --git a/internal/example/grpc/main_proxy.go b/internal/example/grpc/main_proxy.go new file mode 100644 index 00000000..3b9d0bf0 --- /dev/null +++ b/internal/example/grpc/main_proxy.go @@ -0,0 +1,25 @@ +package main + +import ( + "context" + + "github.com/pubgo/funk/log" + _ "github.com/pubgo/lava/core/debug/logdy" + "github.com/pubgo/lava/internal/example/grpc/internal/bootstrap" +) + +func main() { + log.SetEnableChecker(func(ctx context.Context, lvl log.Level, nameOrMessage string, fields log.Map) bool { + //if nameOrMessage == "eval type value" { + // return false + //} + // + //if nameOrMessage == "grpc-server" { + // return false + //} + + return true + }) + + bootstrap.MainProxy() +} diff --git a/internal/example/grpc/openapi.yaml b/internal/example/grpc/openapi.yaml index bfdb6495..542fe415 100644 --- a/internal/example/grpc/openapi.yaml +++ b/internal/example/grpc/openapi.yaml @@ -3,8 +3,7 @@ openapi: 3.0.3 info: - title: Id API - description: Id 生成随机ID服务 + title: "" version: 0.0.1 servers: - url: https:8080 @@ -31,6 +30,24 @@ paths: description: OK content: '*/*': {} + /v1/id/echo: + post: + tags: + - IdProxy + operationId: IdProxy_Echo + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/EchoReq' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/EchoRsp' /v1/id/generate: post: tags: @@ -174,6 +191,16 @@ components: type: string msg: $ref: '#/components/schemas/Message' + EchoReq: + type: object + properties: + hello: + type: string + EchoRsp: + type: object + properties: + hello: + type: string GenerateRequest: type: object properties: @@ -225,3 +252,5 @@ components: description: TypesResponse 返回值类型 tags: - name: Id + description: Id 生成随机ID服务 + - name: IdProxy diff --git a/internal/example/grpc/pkg/proto/gidpb/id.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.pb.go index 22891abd..1a77b48b 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.pb.go @@ -569,50 +569,51 @@ var file_gid_id_proto_rawDesc = []byte{ 0x00, 0x12, 0x08, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x73, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x67, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x68, 0x6f, 0x72, - 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0x9d, 0x05, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x7d, 0x0a, 0x08, - 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, - 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x44, 0xa2, 0xea, 0x30, 0x26, 0x0a, 0x06, 0x69, 0x64, 0x2e, - 0x67, 0x65, 0x6e, 0x1a, 0x10, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x12, - 0x04, 0x74, 0x72, 0x75, 0x65, 0x1a, 0x0a, 0x0a, 0x03, 0x73, 0x73, 0x73, 0x12, 0x03, 0x73, 0x73, - 0x73, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, - 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x4c, 0x0a, 0x0a, 0x54, - 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, - 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, - 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, 0x0a, 0x05, 0x54, 0x79, 0x70, - 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, - 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, - 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, - 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x1a, 0x1d, - 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, - 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x6f, 0x0a, - 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, - 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0xba, 0x47, 0x27, 0x0a, 0x0d, - 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x0a, 0x0e, 0x63, - 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x31, 0x12, 0x06, 0xe8, - 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x3a, 0x03, 0x6d, 0x73, 0x67, - 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, 0x01, 0x30, 0x01, 0x12, 0x31, - 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, - 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, - 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, - 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, - 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, - 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, - 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, - 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, - 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x67, 0x69, 0x64, 0x70, 0x62, - 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xa2, 0x05, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x81, 0x01, 0x0a, + 0x08, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, + 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x15, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x48, 0xa2, 0xea, 0x30, 0x2a, 0x0a, 0x06, 0x69, 0x64, + 0x2e, 0x67, 0x65, 0x6e, 0x1a, 0x0e, 0x0a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x05, 0x77, + 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x10, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x12, 0x04, 0x74, 0x72, 0x75, 0x65, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, + 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, + 0x12, 0x4c, 0x0a, 0x0a, 0x54, 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, + 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, + 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, + 0x0a, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, + 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, + 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, + 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, + 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, + 0x3a, 0x01, 0x2a, 0x1a, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, + 0x64, 0x7d, 0x12, 0x6f, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, + 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, + 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, + 0xba, 0x47, 0x27, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, + 0x61, 0x67, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, + 0x67, 0x31, 0x12, 0x06, 0xe8, 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, + 0x3a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, + 0x01, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, + 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, + 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, + 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, + 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, + 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, + 0x66, 0x69, 0x6c, 0x65, 0x22, 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, + 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, + 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, + 0x67, 0x69, 0x64, 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/internal/example/grpc/pkg/proto/gidpb/proxy.pb.go b/internal/example/grpc/pkg/proto/gidpb/proxy.pb.go new file mode 100644 index 00000000..002bdc71 --- /dev/null +++ b/internal/example/grpc/pkg/proto/gidpb/proxy.pb.go @@ -0,0 +1,213 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.1 +// source: gid/proxy.proto + +package gidpb + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type EchoReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hello string `protobuf:"bytes,1,opt,name=hello,proto3" json:"hello,omitempty"` +} + +func (x *EchoReq) Reset() { + *x = EchoReq{} + if protoimpl.UnsafeEnabled { + mi := &file_gid_proxy_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoReq) ProtoMessage() {} + +func (x *EchoReq) ProtoReflect() protoreflect.Message { + mi := &file_gid_proxy_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EchoReq.ProtoReflect.Descriptor instead. +func (*EchoReq) Descriptor() ([]byte, []int) { + return file_gid_proxy_proto_rawDescGZIP(), []int{0} +} + +func (x *EchoReq) GetHello() string { + if x != nil { + return x.Hello + } + return "" +} + +type EchoRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Hello string `protobuf:"bytes,1,opt,name=hello,proto3" json:"hello,omitempty"` +} + +func (x *EchoRsp) Reset() { + *x = EchoRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_gid_proxy_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoRsp) ProtoMessage() {} + +func (x *EchoRsp) ProtoReflect() protoreflect.Message { + mi := &file_gid_proxy_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EchoRsp.ProtoReflect.Descriptor instead. +func (*EchoRsp) Descriptor() ([]byte, []int) { + return file_gid_proxy_proto_rawDescGZIP(), []int{1} +} + +func (x *EchoRsp) GetHello() string { + if x != nil { + return x.Hello + } + return "" +} + +var File_gid_proxy_proto protoreflect.FileDescriptor + +var file_gid_proxy_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x67, 0x69, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x03, 0x67, 0x69, 0x64, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1f, 0x0a, 0x07, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x12, + 0x14, 0x0a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x1f, 0x0a, 0x07, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x73, 0x70, + 0x12, 0x14, 0x0a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x32, 0x45, 0x0a, 0x07, 0x49, 0x64, 0x50, 0x72, 0x6f, 0x78, + 0x79, 0x12, 0x3a, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x0c, 0x2e, 0x67, 0x69, 0x64, 0x2e, + 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x0c, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x45, 0x63, + 0x68, 0x6f, 0x52, 0x73, 0x70, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, + 0x22, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x42, 0x0f, 0x5a, + 0x0d, 0x2e, 0x2f, 0x67, 0x69, 0x64, 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_gid_proxy_proto_rawDescOnce sync.Once + file_gid_proxy_proto_rawDescData = file_gid_proxy_proto_rawDesc +) + +func file_gid_proxy_proto_rawDescGZIP() []byte { + file_gid_proxy_proto_rawDescOnce.Do(func() { + file_gid_proxy_proto_rawDescData = protoimpl.X.CompressGZIP(file_gid_proxy_proto_rawDescData) + }) + return file_gid_proxy_proto_rawDescData +} + +var file_gid_proxy_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_gid_proxy_proto_goTypes = []any{ + (*EchoReq)(nil), // 0: gid.EchoReq + (*EchoRsp)(nil), // 1: gid.EchoRsp +} +var file_gid_proxy_proto_depIdxs = []int32{ + 0, // 0: gid.IdProxy.Echo:input_type -> gid.EchoReq + 1, // 1: gid.IdProxy.Echo:output_type -> gid.EchoRsp + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_gid_proxy_proto_init() } +func file_gid_proxy_proto_init() { + if File_gid_proxy_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_gid_proxy_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*EchoReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_gid_proxy_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*EchoRsp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_gid_proxy_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_gid_proxy_proto_goTypes, + DependencyIndexes: file_gid_proxy_proto_depIdxs, + MessageInfos: file_gid_proxy_proto_msgTypes, + }.Build() + File_gid_proxy_proto = out.File + file_gid_proxy_proto_rawDesc = nil + file_gid_proxy_proto_goTypes = nil + file_gid_proxy_proto_depIdxs = nil +} diff --git a/internal/example/grpc/pkg/proto/gidpb/proxy_grpc.pb.go b/internal/example/grpc/pkg/proto/gidpb/proxy_grpc.pb.go new file mode 100644 index 00000000..a52d15bc --- /dev/null +++ b/internal/example/grpc/pkg/proto/gidpb/proxy_grpc.pb.go @@ -0,0 +1,107 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v5.27.1 +// source: gid/proxy.proto + +package gidpb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + IdProxy_Echo_FullMethodName = "/gid.IdProxy/Echo" +) + +// IdProxyClient is the client API for IdProxy service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type IdProxyClient interface { + Echo(ctx context.Context, in *EchoReq, opts ...grpc.CallOption) (*EchoRsp, error) +} + +type idProxyClient struct { + cc grpc.ClientConnInterface +} + +func NewIdProxyClient(cc grpc.ClientConnInterface) IdProxyClient { + return &idProxyClient{cc} +} + +func (c *idProxyClient) Echo(ctx context.Context, in *EchoReq, opts ...grpc.CallOption) (*EchoRsp, error) { + out := new(EchoRsp) + err := c.cc.Invoke(ctx, IdProxy_Echo_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// IdProxyServer is the server API for IdProxy service. +// All implementations should embed UnimplementedIdProxyServer +// for forward compatibility +type IdProxyServer interface { + Echo(context.Context, *EchoReq) (*EchoRsp, error) +} + +// UnimplementedIdProxyServer should be embedded to have forward compatible implementations. +type UnimplementedIdProxyServer struct { +} + +func (UnimplementedIdProxyServer) Echo(context.Context, *EchoReq) (*EchoRsp, error) { + return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") +} + +// UnsafeIdProxyServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to IdProxyServer will +// result in compilation errors. +type UnsafeIdProxyServer interface { + mustEmbedUnimplementedIdProxyServer() +} + +func RegisterIdProxyServer(s grpc.ServiceRegistrar, srv IdProxyServer) { + s.RegisterService(&IdProxy_ServiceDesc, srv) +} + +func _IdProxy_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EchoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdProxyServer).Echo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: IdProxy_Echo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdProxyServer).Echo(ctx, req.(*EchoReq)) + } + return interceptor(ctx, in, info, handler) +} + +// IdProxy_ServiceDesc is the grpc.ServiceDesc for IdProxy service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var IdProxy_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "gid.IdProxy", + HandlerType: (*IdProxyServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Echo", + Handler: _IdProxy_Echo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "gid/proxy.proto", +} diff --git a/internal/example/grpc/proto/gid/proxy.proto b/internal/example/grpc/proto/gid/proxy.proto new file mode 100644 index 00000000..f59a7e9f --- /dev/null +++ b/internal/example/grpc/proto/gid/proxy.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package gid; + +import "google/api/annotations.proto"; + +option go_package = "./gidpb;gidpb"; + +service IdProxy { + rpc Echo (EchoReq) returns (EchoRsp) { + option (google.api.http) = { + post: "/v1/id/echo" + body: "*" + }; + } +} + +message EchoReq { + string hello = 1; +} + +message EchoRsp { + string hello = 1; +} \ No newline at end of file diff --git a/lava/router.go b/lava/router.go index 86bdc8ca..023f7b33 100644 --- a/lava/router.go +++ b/lava/router.go @@ -8,6 +8,11 @@ import ( "google.golang.org/grpc" ) +type GrpcProxy interface { + GrpcRouter + Proxy() grpc.ClientConnInterface +} + type GrpcRouter interface { Middlewares() []Middleware ServiceDesc() *grpc.ServiceDesc diff --git a/pkg/gateway/_doc.go b/pkg/gateway/_doc.go index 3a62f359..5f26478f 100644 --- a/pkg/gateway/_doc.go +++ b/pkg/gateway/_doc.go @@ -5,9 +5,9 @@ package gateway // https://github.com/dgrr/http2 // https://github.com/r3labs/sse // https://github.com/googollee/go-socket.io -// https://github.com/connectrpc/vanguard-go/tree/main +// https://github.com/connectrpc/vanguard-go // https://github.com/twitchtv/twirp -// https://github.com/stackrox/go-grpc-http1/blob/main/tools/imports.go +// https://github.com/stackrox/go-grpc-http1 // github.com/improbable-eng/grpc-web // github.com/grpc-ecosystem/grpc-gateway/v2 // https://github.com/nhooyr/websocket diff --git a/pkg/gateway/aaa.go b/pkg/gateway/aaa.go index 5f0ec844..2884f615 100644 --- a/pkg/gateway/aaa.go +++ b/pkg/gateway/aaa.go @@ -1,6 +1,7 @@ package gateway import ( + "context" "io" "net/http" @@ -60,3 +61,7 @@ type StreamCodec interface { type Compressor interface { encoding.Compressor } + +type GrpcMethodHandler = func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) +type GrpcStreamHandler = grpc.StreamHandler +type StreamDirector func(ctx context.Context, fullMethodName string) (context.Context, grpc.ClientConnInterface, error) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index a0bae5ba..089d9ec1 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -14,6 +14,7 @@ import ( "github.com/fullstorydev/grpchan/inprocgrpc" "github.com/gofiber/adaptor/v2" "github.com/gofiber/fiber/v2" + _ "github.com/mwitkow/grpc-proxy/proxy" "github.com/pubgo/funk/assert" "github.com/pubgo/funk/errors" "github.com/pubgo/funk/generic" @@ -204,12 +205,13 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { return errors.Format("grpc method not found, method=%s", matchOperation.Operation) } - md := metadata.New(nil) + md := metadata.MD{} for k, v := range ctx.GetReqHeaders() { md.Append(k, v...) } rspCtx := metadata.NewIncomingContext(ctx.Context(), md) + return errors.WrapCaller(mth.Handle(&streamHTTP{ handler: ctx, ctx: rspCtx, @@ -295,6 +297,12 @@ func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor) { m.cc.WithServerStreamInterceptor(interceptor) } +func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcProxy) { + if err := m.registerService(sd, proxy); err != nil { + log.Fatal().Err(err).Msgf("gateway: RegisterProxy error: %v", err) + } +} + // RegisterService satisfies grpc.ServiceRegistrar for generated service code hooks. func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { assert.If(generic.IsNil(ss), "ss params is nil") @@ -318,8 +326,25 @@ func (m *Mux) registerRouter(rule *methodWrapper) { m.opts.customOperationNames[rule.meta.Name] = rule } - assert.Exit(m.routerTree.Add(http.MethodPost, rule.grpcFullMethod, rule.grpcFullMethod, - resolveBodyDesc(rule.grpcMethodPbDesc, "*", "*"))) + rule.inputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Input().FullName())) + rule.outputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Output().FullName())) + + if rule.srv.grpcProxyCli != nil { + if rule.grpcMethodDesc != nil { + rule.grpcMethodDesc.Handler = grpcMethodHandlerWrapper(rule) + } + + if rule.grpcStreamDesc != nil { + rule.grpcStreamDesc.Handler = grpcMethodStreamWrapper(rule) + } + } + + assert.Exit(m.routerTree.Add( + http.MethodPost, + rule.grpcFullMethod, + rule.grpcFullMethod, + resolveBodyDesc(rule.grpcMethodProtoDesc, "*", "*")), + ) } func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { @@ -340,6 +365,10 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { servicePbDesc: sd, } + if p, ok := ss.(lava.GrpcProxy); ok && p != nil { + srv.grpcProxyCli = p.Proxy() + } + findMethodDesc := func(methodName string) protoreflect.MethodDescriptor { md := sd.Methods().ByName(protoreflect.Name(methodName)) assert.If(md == nil, "missing protobuf descriptor for %v", methodName) @@ -354,11 +383,11 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { assert.If(m.opts.handlers[grpcMethod] != nil, "grpc httpPathRule has existed") m.registerRouter(&methodWrapper{ - srv: srv, - grpcMethodDesc: grpcMth, - grpcMethodPbDesc: methodDesc, - grpcFullMethod: grpcMethod, - meta: getExtensionRpc(methodDesc), + srv: srv, + grpcMethodDesc: grpcMth, + grpcMethodProtoDesc: methodDesc, + grpcFullMethod: grpcMethod, + meta: getExtensionRpc(methodDesc), }) assert.Exit(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { @@ -374,11 +403,11 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { methodDesc := findMethodDesc(grpcMth.StreamName) m.registerRouter(&methodWrapper{ - srv: srv, - grpcStreamDesc: grpcMth, - grpcMethodPbDesc: methodDesc, - grpcFullMethod: grpcMethod, - meta: getExtensionRpc(methodDesc), + srv: srv, + grpcStreamDesc: grpcMth, + grpcMethodProtoDesc: methodDesc, + grpcFullMethod: grpcMethod, + meta: getExtensionRpc(methodDesc), }) assert.Exit(handlerHttpRoute(getExtensionHTTP(methodDesc), func(mth string, path string, reqBody, rspBody string) error { @@ -412,7 +441,7 @@ func handleOperation(opt *methodWrapper) *GrpcMethod { SrvDesc: opt.srv.serviceDesc, GrpcMethodDesc: opt.grpcMethodDesc, GrpcStreamDesc: opt.grpcStreamDesc, - MethodDesc: opt.grpcMethodPbDesc, + MethodDesc: opt.grpcMethodProtoDesc, GrpcFullMethod: opt.grpcFullMethod, Meta: opt.meta, } diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index d3bc3699..49808116 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -134,7 +134,7 @@ func (s *streamHTTP) RecvMsg(m interface{}) error { if len(s.handler.Body()) > 0 { if err := protojson.Unmarshal(s.handler.Body(), msg); err != nil { - return errors.Wrap(err, "failed to unmarshal body by proto-json") + return errors.Wrapf(err, "failed to unmarshal body by proto-json, msg=%#v", msg) } } } diff --git a/pkg/gateway/stream_proxy.go b/pkg/gateway/stream_proxy.go index 2860c3ce..7bd92507 100644 --- a/pkg/gateway/stream_proxy.go +++ b/pkg/gateway/stream_proxy.go @@ -1,44 +1,139 @@ +// Copyright 2017 Michal Witkowski. All Rights Reserved. +// See LICENSE for licensing terms. + package gateway import ( "context" + "io" "google.golang.org/grpc" - "google.golang.org/grpc/metadata" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" ) -var _ grpc.ServerStream = (*serverProxyStream)(nil) - -type serverProxyStream struct { - cli grpc.ClientStream -} +var ( + clientStreamDescForProxying = &grpc.StreamDesc{ + ServerStreams: true, + ClientStreams: true, + } +) -func (s serverProxyStream) SetHeader(md metadata.MD) error { - //TODO implement me - panic("implement me") +// TransparentHandler returns a handler that attempts to proxy all requests that are not registered in the server. +// The indented use here is as a transparent proxy, where the server doesn't know about the services implemented by the +// backends. It should be used as a `grpc.UnknownServiceHandler`. +func TransparentHandler(director StreamDirector) grpc.StreamHandler { + streamer := &handler{director: director} + return streamer.handler } -func (s serverProxyStream) SendHeader(md metadata.MD) error { - //TODO implement me - panic("implement me") +type handler struct { + director StreamDirector } -func (s serverProxyStream) SetTrailer(md metadata.MD) { - //TODO implement me - panic("implement me") -} +// handler is where the real magic of proxying happens. +// It is invoked like any gRPC server stream and uses the emptypb.Empty type server +// to proxy calls between the input and output streams. +func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error { + // little bit of gRPC internals never hurt anyone + fullMethodName, ok := grpc.MethodFromServerStream(serverStream) + if !ok { + return status.Errorf(codes.Internal, "lowLevelServerStream not exists in context") + } + // We require that the director's returned context inherits from the serverStream.Context(). + outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName) + if err != nil { + return err + } -func (s serverProxyStream) Context() context.Context { - //TODO implement me - panic("implement me") + clientCtx, clientCancel := context.WithCancel(outgoingCtx) + defer clientCancel() + clientStream, err := backendConn.NewStream(clientCtx, clientStreamDescForProxying, fullMethodName) + if err != nil { + return err + } + // Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate. + // Channels do not have to be closed, it is just a control flow mechanism, see + // https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ + s2cErrChan := s.forwardServerToClient(serverStream, clientStream) + c2sErrChan := s.forwardClientToServer(clientStream, serverStream) + // We don't know which side is going to stop sending first, so we need a select between the two. + for i := 0; i < 2; i++ { + select { + case s2cErr := <-s2cErrChan: + if s2cErr == io.EOF { + // this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./ + // the clientStream>serverStream may continue pumping though. + clientStream.CloseSend() + } else { + // however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need + // to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and + // exit with an error to the stack + clientCancel() + return status.Errorf(codes.Internal, "failed proxying s2c: %v", s2cErr) + } + case c2sErr := <-c2sErrChan: + // This happens when the clientStream has nothing else to offer (io.EOF), returned a gRPC error. In those two + // cases we may have received Trailers as part of the call. In case of other errors (stream closed) the trailers + // will be nil. + serverStream.SetTrailer(clientStream.Trailer()) + // c2sErr will contain RPC error from client code. If not io.EOF return the RPC error as server stream error. + if c2sErr != io.EOF { + return c2sErr + } + return nil + } + } + return status.Errorf(codes.Internal, "gRPC proxying should never reach this stage.") } -func (s serverProxyStream) SendMsg(m any) error { - //TODO implement me - panic("implement me") +func (s *handler) forwardClientToServer(src grpc.ClientStream, dst grpc.ServerStream) chan error { + ret := make(chan error, 1) + go func() { + f := &emptypb.Empty{} + for i := 0; ; i++ { + if err := src.RecvMsg(f); err != nil { + ret <- err // this can be io.EOF which is happy case + break + } + if i == 0 { + // This is a bit of a hack, but client to server headers are only readable after first client msg is + // received but must be written to server stream before the first msg is flushed. + // This is the only place to do it nicely. + md, err := src.Header() + if err != nil { + ret <- err + break + } + if err := dst.SendHeader(md); err != nil { + ret <- err + break + } + } + if err := dst.SendMsg(f); err != nil { + ret <- err + break + } + } + }() + return ret } -func (s serverProxyStream) RecvMsg(m any) error { - //TODO implement me - panic("implement me") +func (s *handler) forwardServerToClient(src grpc.ServerStream, dst grpc.ClientStream) chan error { + ret := make(chan error, 1) + go func() { + f := &emptypb.Empty{} + for i := 0; ; i++ { + if err := src.RecvMsg(f); err != nil { + ret <- err // this can be io.EOF which is happy case + break + } + if err := dst.SendMsg(f); err != nil { + ret <- err + break + } + } + }() + return ret } diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index 406928a9..67a95436 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -1,6 +1,8 @@ package gateway import ( + "context" + "github.com/pubgo/funk/errors" "github.com/pubgo/lava/pkg/proto/lavapbv1" "google.golang.org/grpc" @@ -12,6 +14,7 @@ type serviceWrapper struct { srv any serviceDesc *grpc.ServiceDesc servicePbDesc protoreflect.ServiceDescriptor + grpcProxyCli grpc.ClientConnInterface } type GrpcMethod struct { @@ -27,10 +30,13 @@ type GrpcMethod struct { } type methodWrapper struct { - srv *serviceWrapper - grpcMethodDesc *grpc.MethodDesc - grpcStreamDesc *grpc.StreamDesc - grpcMethodPbDesc protoreflect.MethodDescriptor + srv *serviceWrapper + grpcMethodDesc *grpc.MethodDesc + grpcStreamDesc *grpc.StreamDesc + grpcMethodProtoDesc protoreflect.MethodDescriptor + + inputType protoreflect.MessageType + outputType protoreflect.MessageType // /{ServiceName}/{MethodName} grpcFullMethod string @@ -47,7 +53,7 @@ func (h methodWrapper) Handle(stream grpc.ServerStream) error { } return errors.WrapCaller(stream.SendMsg(reply)) - } else { + } else if h.grpcStreamDesc != nil { info := &grpc.StreamServerInfo{ FullMethod: h.grpcFullMethod, IsClientStream: h.grpcStreamDesc.ClientStreams, @@ -59,5 +65,38 @@ func (h methodWrapper) Handle(stream grpc.ServerStream) error { } else { return errors.WrapCaller(h.grpcStreamDesc.Handler(h.srv.srv, stream)) } + } else { + return errors.Format("cannot find server handler") } } + +func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcMethodHandler { + return func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) { + var in = mth.inputType.New().Interface() + if err := dec(in); err != nil { + return nil, errors.WrapCaller(err) + } + + var h = func(ctx context.Context, req any) (any, error) { + var out = mth.outputType.New().Interface() + err := mth.srv.grpcProxyCli.Invoke(ctx, mth.grpcFullMethod, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil + } + + // 获取 server header 并转换成 client header + if interceptor == nil { + return h(ctx, in) + } + + return interceptor(ctx, in, &grpc.UnaryServerInfo{FullMethod: mth.grpcFullMethod}, h) + } +} + +func grpcMethodStreamWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcStreamHandler { + return TransparentHandler(func(ctx context.Context, fullMethodName string) (context.Context, grpc.ClientConnInterface, error) { + return ctx, mth.srv.grpcProxyCli, nil + }) +} diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index 40708ff8..b88dcb9f 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -80,8 +80,9 @@ func (s *serviceImpl) Start() { s.start() } func (s *serviceImpl) Stop() { s.stop() } func (s *serviceImpl) DixInject( - handlers []lava.GrpcRouter, + grpcRouters []lava.GrpcRouter, httpRouters []lava.HttpRouter, + grpcProxy []lava.GrpcProxy, dixMiddlewares []lava.Middleware, getLifecycle lifecycle.Getter, lifecycle lifecycle.Lifecycle, @@ -193,7 +194,7 @@ func (s *serviceImpl) DixInject( } } - for _, handler := range handlers { + for _, handler := range grpcRouters { //srv := doc.WithService() //for _, an := range h.Annotation() { // switch a := an.(type) { @@ -324,7 +325,7 @@ func (s *serviceImpl) DixInject( mux = gw[0] } srvMidMap := make(map[string][]lava.Middleware) - for _, h := range handlers { + for _, h := range grpcRouters { desc := h.ServiceDesc() assert.If(desc == nil, "desc is nil") @@ -350,6 +351,28 @@ func (s *serviceImpl) DixInject( } } + for _, h := range grpcProxy { + desc := h.ServiceDesc() + assert.If(desc == nil, "desc is nil") + + srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], globalMiddlewares...) + srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], h.Middlewares()...) + + if m, ok := h.(lava.Close); ok { + lifecycle.BeforeStop(m.Close) + } + + if m, ok := h.(lava.Initializer); ok { + s.initList = append(s.initList, m.Initialize) + } + + if m, ok := h.(lava.Init); ok { + s.initList = append(s.initList, m.Init) + } + + mux.RegisterProxy(desc, h) + } + mux.SetUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) mux.SetStreamInterceptor(handlerStreamMiddle(srvMidMap)) s.cc = s.cc.WithServerUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) @@ -361,7 +384,7 @@ func (s *serviceImpl) DixInject( grpc.ChainStreamInterceptor(handlerStreamMiddle(srvMidMap)), ).Expect("failed to build grpc server") - for _, h := range handlers { + for _, h := range grpcRouters { grpcServer.RegisterService(h.ServiceDesc(), h) } From 3c8796f2f63d7f2c0e0743f60f2ee20228376d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Wed, 24 Jul 2024 21:42:35 +0800 Subject: [PATCH 28/41] fix: barry 2024-07-24 21:42:35 --- pkg/gateway/mux.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 089d9ec1..260b331d 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -211,7 +211,6 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { } rspCtx := metadata.NewIncomingContext(ctx.Context(), md) - return errors.WrapCaller(mth.Handle(&streamHTTP{ handler: ctx, ctx: rspCtx, From 1f9e55b9db38a851bd8528b7bf1b7f7b3651dd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Wed, 24 Jul 2024 22:24:43 +0800 Subject: [PATCH 29/41] fix: barry 2024-07-24 22:24:43 --- pkg/gateway/mux.go | 38 +++++++++++++++++++++++++------------- pkg/gateway/stream_http.go | 12 ++++++------ pkg/gateway/wrapper.go | 14 +++++++------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 260b331d..591c0721 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -129,9 +129,9 @@ func CompressorOption(contentEncoding string, c Compressor) MuxOption { var _ Gateway = (*Mux)(nil) type Mux struct { - cc *inprocgrpc.Channel - opts *muxOptions - routerTree *routertree.RouteTree + localClient *inprocgrpc.Channel + opts *muxOptions + routerTree *routertree.RouteTree } func (m *Mux) GetRouteMethods() []RouteOperation { return m.routerTree.List() } @@ -221,11 +221,23 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { } func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts ...grpc.CallOption) error { - return m.cc.Invoke(ctx, method, args, reply, opts...) + if mth := m.opts.handlers[method]; mth != nil { + if mth.srv.remoteProxyCli != nil { + return mth.srv.remoteProxyCli.Invoke(ctx, method, args, reply, opts...) + } + } + + return m.localClient.Invoke(ctx, method, args, reply, opts...) } func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) { - return m.cc.NewStream(ctx, desc, method, opts...) + if mth := m.opts.handlers[method]; mth != nil { + if mth.srv.remoteProxyCli != nil { + return mth.srv.remoteProxyCli.NewStream(ctx, desc, method, opts...) + } + } + + return m.localClient.NewStream(ctx, desc, method, opts...) } func (m *Mux) ServeHTTP(writer http.ResponseWriter, request *http.Request) { @@ -276,9 +288,9 @@ func NewMux(opts ...MuxOption) *Mux { sort.Strings(muxOpts.encodingTypeOffers) mux := &Mux{ - opts: &muxOpts, - cc: new(inprocgrpc.Channel), - routerTree: routertree.NewRouteTree(), + opts: &muxOpts, + localClient: new(inprocgrpc.Channel), + routerTree: routertree.NewRouteTree(), } return mux @@ -286,14 +298,14 @@ func NewMux(opts ...MuxOption) *Mux { func (m *Mux) SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) { m.opts.unaryInterceptor = interceptor - m.cc.WithServerUnaryInterceptor(interceptor) + m.localClient.WithServerUnaryInterceptor(interceptor) } // SetStreamInterceptor configures the in-process channel to use the // given server interceptor for streaming RPCs when dispatching. func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor) { m.opts.streamInterceptor = interceptor - m.cc.WithServerStreamInterceptor(interceptor) + m.localClient.WithServerStreamInterceptor(interceptor) } func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcProxy) { @@ -306,7 +318,7 @@ func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcProxy) { func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { assert.If(generic.IsNil(ss), "ss params is nil") - m.cc.RegisterService(sd, ss) + m.localClient.RegisterService(sd, ss) ht := reflect.TypeOf(sd.HandlerType).Elem() st := reflect.TypeOf(ss) @@ -328,7 +340,7 @@ func (m *Mux) registerRouter(rule *methodWrapper) { rule.inputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Input().FullName())) rule.outputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Output().FullName())) - if rule.srv.grpcProxyCli != nil { + if rule.srv.remoteProxyCli != nil { if rule.grpcMethodDesc != nil { rule.grpcMethodDesc.Handler = grpcMethodHandlerWrapper(rule) } @@ -365,7 +377,7 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { } if p, ok := ss.(lava.GrpcProxy); ok && p != nil { - srv.grpcProxyCli = p.Proxy() + srv.remoteProxyCli = p.Proxy() } findMethodDesc := func(methodName string) protoreflect.MethodDescriptor { diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index 49808116..27afecc8 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -82,9 +82,9 @@ func (s *streamHTTP) SendMsg(m interface{}) error { msg := cur.Interface() reqName := msg.ProtoReflect().Descriptor().FullName() - handler := s.method.srv.opts.responseInterceptors[reqName] - if handler != nil { - return errors.Wrapf(handler(s.handler, msg), "failed to handler response data by %s", reqName) + rspInterceptor := s.method.srv.opts.responseInterceptors[reqName] + if rspInterceptor != nil { + return errors.Wrapf(rspInterceptor(s.handler, msg), "failed to do rsp interceptor response data by %s", reqName) } b, err := protojson.Marshal(msg) @@ -119,9 +119,9 @@ func (s *streamHTTP) RecvMsg(m interface{}) error { msg := cur.Interface() reqName := msg.ProtoReflect().Descriptor().FullName() - handler := s.method.srv.opts.requestInterceptors[reqName] - if handler != nil { - return errors.Wrapf(handler(s.handler, msg), "failed to handler request data by %s", reqName) + reqInterceptor := s.method.srv.opts.requestInterceptors[reqName] + if reqInterceptor != nil { + return errors.Wrapf(reqInterceptor(s.handler, msg), "failed to go req interceptor request data by %s", reqName) } if method == http.MethodPut || diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index 67a95436..56d059c0 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -10,11 +10,11 @@ import ( ) type serviceWrapper struct { - opts *muxOptions - srv any - serviceDesc *grpc.ServiceDesc - servicePbDesc protoreflect.ServiceDescriptor - grpcProxyCli grpc.ClientConnInterface + opts *muxOptions + srv any + serviceDesc *grpc.ServiceDesc + servicePbDesc protoreflect.ServiceDescriptor + remoteProxyCli grpc.ClientConnInterface } type GrpcMethod struct { @@ -79,7 +79,7 @@ func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcM var h = func(ctx context.Context, req any) (any, error) { var out = mth.outputType.New().Interface() - err := mth.srv.grpcProxyCli.Invoke(ctx, mth.grpcFullMethod, in, out, opts...) + err := mth.srv.remoteProxyCli.Invoke(ctx, mth.grpcFullMethod, in, out, opts...) if err != nil { return nil, err } @@ -97,6 +97,6 @@ func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcM func grpcMethodStreamWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcStreamHandler { return TransparentHandler(func(ctx context.Context, fullMethodName string) (context.Context, grpc.ClientConnInterface, error) { - return ctx, mth.srv.grpcProxyCli, nil + return ctx, mth.srv.remoteProxyCli, nil }) } From 1aa8b6beff1e182151e3ac270cd4ef955c55516c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Wed, 24 Jul 2024 22:34:38 +0800 Subject: [PATCH 30/41] fix: barry 2024-07-24 22:34:38 --- pkg/gateway/stream_proxy.go | 14 +++++++++----- pkg/gateway/wrapper.go | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/gateway/stream_proxy.go b/pkg/gateway/stream_proxy.go index 7bd92507..f471fcfa 100644 --- a/pkg/gateway/stream_proxy.go +++ b/pkg/gateway/stream_proxy.go @@ -7,6 +7,7 @@ import ( "context" "io" + "github.com/pubgo/funk/errors" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -23,13 +24,14 @@ var ( // TransparentHandler returns a handler that attempts to proxy all requests that are not registered in the server. // The indented use here is as a transparent proxy, where the server doesn't know about the services implemented by the // backends. It should be used as a `grpc.UnknownServiceHandler`. -func TransparentHandler(director StreamDirector) grpc.StreamHandler { - streamer := &handler{director: director} +func TransparentHandler(director StreamDirector, opts ...grpc.CallOption) grpc.StreamHandler { + streamer := &handler{director: director, opts: opts} return streamer.handler } type handler struct { director StreamDirector + opts []grpc.CallOption } // handler is where the real magic of proxying happens. @@ -41,18 +43,20 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error if !ok { return status.Errorf(codes.Internal, "lowLevelServerStream not exists in context") } + // We require that the director's returned context inherits from the serverStream.Context(). outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName) if err != nil { - return err + return errors.WrapCaller(err) } clientCtx, clientCancel := context.WithCancel(outgoingCtx) defer clientCancel() - clientStream, err := backendConn.NewStream(clientCtx, clientStreamDescForProxying, fullMethodName) + clientStream, err := backendConn.NewStream(clientCtx, clientStreamDescForProxying, fullMethodName, s.opts...) if err != nil { - return err + return errors.WrapCaller(err) } + // Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate. // Channels do not have to be closed, it is just a control flow mechanism, see // https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index 56d059c0..5927d7bb 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -2,7 +2,6 @@ package gateway import ( "context" - "github.com/pubgo/funk/errors" "github.com/pubgo/lava/pkg/proto/lavapbv1" "google.golang.org/grpc" @@ -98,5 +97,5 @@ func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcM func grpcMethodStreamWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcStreamHandler { return TransparentHandler(func(ctx context.Context, fullMethodName string) (context.Context, grpc.ClientConnInterface, error) { return ctx, mth.srv.remoteProxyCli, nil - }) + }, opts...) } From 08409d43e82a62d44cb39f6710369447485894d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 01:10:27 +0800 Subject: [PATCH 31/41] fix: barry 2024-07-26 01:10:27 --- clients/grpcc/grpcc_config/config.go | 11 +- clients/grpcc/grpcc_config/grpc.go | 22 +- cmds/app/cmd.go | 4 +- go.mod | 2 +- go.sum | 19 +- internal/example/grpc/Makefile | 4 +- internal/example/grpc/docs/api.http | 1 + .../handlers/gid_handler/handler_proxy.go | 7 +- internal/example/grpc/main.go | 3 + lava/router.go | 11 +- pkg/gateway/context.go | 353 ++++++++++++++++++ pkg/gateway/mux.go | 96 ++--- pkg/gateway/stream_http.go | 16 +- pkg/gateway/wrapper.go | 55 +-- servers/grpcs/inner_server.go | 90 ++++- servers/grpcs/middleware.go | 3 +- servers/grpcs/server.go | 26 +- .../{metadata => metadataservice}/service.go | 2 +- 18 files changed, 600 insertions(+), 125 deletions(-) create mode 100644 pkg/gateway/context.go rename services/{metadata => metadataservice}/service.go (99%) diff --git a/clients/grpcc/grpcc_config/config.go b/clients/grpcc/grpcc_config/config.go index 0a0380db..0db9a561 100644 --- a/clients/grpcc/grpcc_config/config.go +++ b/clients/grpcc/grpcc_config/config.go @@ -3,10 +3,9 @@ package grpcc_config import ( "time" + "github.com/pubgo/lava/clients/grpcc/grpcc_resolver" "google.golang.org/grpc" "google.golang.org/grpc/resolver" - - "github.com/pubgo/lava/clients/grpcc/grpcc_resolver" ) const ( @@ -57,20 +56,20 @@ func DefaultCfg() *Cfg { MaxHeaderListSize: 1024 * 4, MaxRecvMsgSize: 1024 * 1024 * 4, // refer: https://github.com/grpc/grpc-go/blob/master/examples/features/keepalive/client/main.go - ClientParameters: clientParameters{ + ClientParameters: ClientParameters{ PermitWithoutStream: true, // send pings even without active streams Time: 10 * time.Second, // send pings every 10 seconds if there is no activity Timeout: 5 * time.Second, // wait 2 second for ping ack before considering the connection dead }, - ConnectParams: connectParams{ - Backoff: backoffConfig{ + ConnectParams: ConnectParams{ + Backoff: BackoffConfig{ Multiplier: 1.6, Jitter: 0.2, BaseDelay: 1.0 * time.Second, MaxDelay: 120 * time.Second, }, }, - Call: callParameters{ + Call: CallParameters{ MaxCallRecvMsgSize: 1024 * 1024 * 4, // DefaultMaxSendMsgSize maximum message that Service can send (4 MB). MaxCallSendMsgSize: 1024 * 1024 * 4, diff --git a/clients/grpcc/grpcc_config/grpc.go b/clients/grpcc/grpcc_config/grpc.go index 456cfa85..fb8869c3 100644 --- a/clients/grpcc/grpcc_config/grpc.go +++ b/clients/grpcc/grpcc_config/grpc.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc/keepalive" ) -type callParameters struct { +type CallParameters struct { Header map[string]string `json:"header"` Trailer map[string]string `json:"trailer"` WaitForReady bool `json:"wait_for_ready"` @@ -23,13 +23,13 @@ type callParameters struct { MaxRetryRPCBufferSize int `json:"max_retry_rpc_buffer_size"` } -type clientParameters struct { +type ClientParameters struct { PermitWithoutStream bool `json:"permit_without_stream"` Time time.Duration `json:"time"` Timeout time.Duration `json:"timeout"` } -func (t clientParameters) toClientParameters() keepalive.ClientParameters { +func (t ClientParameters) toClientParameters() keepalive.ClientParameters { return keepalive.ClientParameters{ PermitWithoutStream: t.PermitWithoutStream, Time: t.Time, @@ -37,20 +37,20 @@ func (t clientParameters) toClientParameters() keepalive.ClientParameters { } } -// backoffConfig defines the configuration options for backoff. -type backoffConfig struct { +// BackoffConfig defines the configuration options for backoff. +type BackoffConfig struct { BaseDelay time.Duration `json:"base_delay"` Multiplier float64 `json:"multiplier"` Jitter float64 `json:"jitter"` MaxDelay time.Duration `json:"max_delay"` } -type connectParams struct { - Backoff backoffConfig `json:"backoff"` +type ConnectParams struct { + Backoff BackoffConfig `json:"backoff"` MinConnectTimeout time.Duration `json:"min_connect_timeout"` } -func (t connectParams) toConnectParams() grpc.ConnectParams { +func (t ConnectParams) toConnectParams() grpc.ConnectParams { return grpc.ConnectParams{ Backoff: backoff.Config{ BaseDelay: t.Backoff.BaseDelay, @@ -92,9 +92,9 @@ type GrpcClientCfg struct { MaxRecvMsgSize int `json:"max_recv_msg_size"` NoProxy bool `json:"no_proxy"` Proxy bool `json:"proxy"` - ConnectParams connectParams `json:"connect_params"` - ClientParameters clientParameters `json:"client_parameters"` - Call callParameters `json:"call"` + ConnectParams ConnectParams `json:"connect_params"` + ClientParameters ClientParameters `json:"client_parameters"` + Call CallParameters `json:"call"` } func (t GrpcClientCfg) ToOpts() []grpc.DialOption { diff --git a/cmds/app/cmd.go b/cmds/app/cmd.go index d9ec3f9f..1e8e5b15 100644 --- a/cmds/app/cmd.go +++ b/cmds/app/cmd.go @@ -28,7 +28,7 @@ import ( "github.com/pubgo/lava/internal/middlewares/middleware_metric" "github.com/pubgo/lava/pkg/cmdutil" "github.com/pubgo/lava/services/errorservice" - "github.com/pubgo/lava/services/metadata" + "github.com/pubgo/lava/services/metadataservice" _ "github.com/pubgo/lava/core/debug/debug" // debug @@ -69,7 +69,7 @@ var defaultProviders = []any{ lifecycle.New, scheduler.New, - metadata.New, + metadataservice.New, errorservice.New, } diff --git a/go.mod b/go.mod index 8407cfbd..f8863762 100644 --- a/go.mod +++ b/go.mod @@ -57,12 +57,12 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 + github.com/joho/godotenv v1.5.1 github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 github.com/libp2p/go-yamux/v4 v4.0.1 github.com/logdyhq/logdy-core v0.13.0 github.com/maragudk/gomponents v0.20.0 github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e - github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 github.com/prometheus/common v0.48.0 github.com/pubgo/dix v0.3.17 github.com/pubgo/funk v0.5.48 diff --git a/go.sum b/go.sum index 6d0a79dd..8c145090 100644 --- a/go.sum +++ b/go.sum @@ -114,7 +114,6 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.12.0 h1:4X+VP1GHd1Mhj6IB5mMeGbLCleqxjletLK6K0rbxyZI= github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0= @@ -217,8 +216,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 h1:0VpGH+cDhbDtdcweoyCVsF3fhN8kejK6rFe/2FFX2nU= @@ -331,6 +328,8 @@ github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/ github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -443,8 +442,6 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 h1:62uLwA3l2JMH84liO4ZhnjTH5PjFyCYxbHLgXPaJMtI= -github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= @@ -673,7 +670,6 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -699,8 +695,6 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= -golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -740,12 +734,8 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -791,10 +781,8 @@ golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= @@ -812,7 +800,6 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20210401141331-865547bb08e2/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240521202816-d264139d666e h1:SkdGTrROJl2jRGT/Fxv5QUf9jtdKCQh4KQJXbXVLAi0= @@ -824,7 +811,6 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= @@ -898,4 +884,3 @@ gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= diff --git a/internal/example/grpc/Makefile b/internal/example/grpc/Makefile index 46daff13..8773ed0f 100644 --- a/internal/example/grpc/Makefile +++ b/internal/example/grpc/Makefile @@ -13,10 +13,10 @@ LDFLAGS=-ldflags " \ " run_proxy: - enable_debug=true go run ${LDFLAGS} -v main_proxy.go grpc + enable_debug=true server_grpc_port=50052 server_http_port=8081 go run ${LDFLAGS} -v main_proxy.go grpc run: - enable_debug=true server_grpc_port=50052 server_http_port=8081 go run ${LDFLAGS} -v main.go grpc + enable_debug=true server_grpc_port=50051 server_http_port=8080 go run ${LDFLAGS} -v main.go grpc .PHONY: build build-gid: diff --git a/internal/example/grpc/docs/api.http b/internal/example/grpc/docs/api.http index 76d63e05..55da651e 100644 --- a/internal/example/grpc/docs/api.http +++ b/internal/example/grpc/docs/api.http @@ -1,5 +1,6 @@ ### GET http://localhost:8080/gid/gw/v1/id/types/hello/111 +Content-Type: application/json ### diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go index 782efe40..ecdb6995 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go @@ -3,9 +3,7 @@ package gid_handler import ( "context" "fmt" - "google.golang.org/grpc/credentials/insecure" - "github.com/pubgo/funk/assert" "github.com/pubgo/lava/internal/example/grpc/pkg/proto/gidpb" "github.com/pubgo/lava/lava" "google.golang.org/grpc" @@ -38,6 +36,7 @@ func (i IdProxy) Middlewares() []lava.Middleware { func (i IdProxy) ServiceDesc() *grpc.ServiceDesc { return &gidpb.IdProxy_ServiceDesc } -func (i IdProxy) Proxy() grpc.ClientConnInterface { - return assert.Must1(grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))) +func (i IdProxy) Proxy() lava.ProxyCfg { + //return assert.Must1(grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))) + return lava.ProxyCfg{Addr: "localhost:50052"} } diff --git a/internal/example/grpc/main.go b/internal/example/grpc/main.go index 4a12d761..f2b78425 100644 --- a/internal/example/grpc/main.go +++ b/internal/example/grpc/main.go @@ -2,13 +2,16 @@ package main import ( "context" + "github.com/pubgo/funk/env" + _ "github.com/joho/godotenv" "github.com/pubgo/funk/log" _ "github.com/pubgo/lava/core/debug/logdy" "github.com/pubgo/lava/internal/example/grpc/internal/bootstrap" ) func main() { + env.Get() log.SetEnableChecker(func(ctx context.Context, lvl log.Level, nameOrMessage string, fields log.Map) bool { //if nameOrMessage == "eval type value" { // return false diff --git a/lava/router.go b/lava/router.go index 023f7b33..a193f0f8 100644 --- a/lava/router.go +++ b/lava/router.go @@ -8,9 +8,18 @@ import ( "google.golang.org/grpc" ) +type ProxyCfg struct { + // Name service name + Name string `yaml:"name"` + // Addr service address + Addr string `yaml:"addr"` + // Resolver service resolver, default direct + Resolver string `yaml:"resolver"` +} + type GrpcProxy interface { GrpcRouter - Proxy() grpc.ClientConnInterface + Proxy() ProxyCfg } type GrpcRouter interface { diff --git a/pkg/gateway/context.go b/pkg/gateway/context.go new file mode 100644 index 00000000..ea16ff73 --- /dev/null +++ b/pkg/gateway/context.go @@ -0,0 +1,353 @@ +package gateway + +import ( + "context" + "fmt" + "strconv" + "strings" + "sync" + "time" + + "google.golang.org/grpc/metadata" +) + +// MetadataHeaderPrefix is the http prefix that represents custom metadata +// parameters to or from a gRPC call. +const MetadataHeaderPrefix = "Grpc-Metadata-" + +// MetadataPrefix is prepended to permanent HTTP header keys (as specified +// by the IANA) when added to the gRPC context. +const MetadataPrefix = "grpcgateway-" + +// MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to +// HTTP headers in a response handled by grpc-gateway +const MetadataTrailerPrefix = "Grpc-Trailer-" + +const metadataGrpcTimeout = "Grpc-Timeout" +const metadataHeaderBinarySuffix = "-Bin" + +const xForwardedFor = "X-Forwarded-For" +const xForwardedHost = "X-Forwarded-Host" + +// DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound +// header isn't present. If the value is 0 the sent `context` will not have a timeout. +var DefaultContextTimeout = 0 * time.Second + +// malformedHTTPHeaders lists the headers that the gRPC server may reject outright as malformed. +// See https://github.com/grpc/grpc-go/pull/4803#issuecomment-986093310 for more context. +var malformedHTTPHeaders = map[string]struct{}{ + "connection": {}, +} + +type ( + rpcMethodKey struct{} + httpPathPatternKey struct{} + + AnnotateContextOption func(ctx context.Context) context.Context +) + +func WithHTTPPathPattern(pattern string) AnnotateContextOption { + return func(ctx context.Context) context.Context { + return withHTTPPathPattern(ctx, pattern) + } +} + +func isValidGRPCMetadataKey(key string) bool { + // Must be a valid gRPC "Header-Name" as defined here: + // https://github.com/grpc/grpc/blob/4b05dc88b724214d0c725c8e7442cbc7a61b1374/doc/PROTOCOL-HTTP2.md + // This means 0-9 a-z _ - . + // Only lowercase letters are valid in the wire protocol, but the client library will normalize + // uppercase ASCII to lowercase, so uppercase ASCII is also acceptable. + bytes := []byte(key) // gRPC validates strings on the byte level, not Unicode. + for _, ch := range bytes { + validLowercaseLetter := ch >= 'a' && ch <= 'z' + validUppercaseLetter := ch >= 'A' && ch <= 'Z' + validDigit := ch >= '0' && ch <= '9' + validOther := ch == '.' || ch == '-' || ch == '_' + if !validLowercaseLetter && !validUppercaseLetter && !validDigit && !validOther { + return false + } + } + return true +} + +func isValidGRPCMetadataTextValue(textValue string) bool { + // Must be a valid gRPC "ASCII-Value" as defined here: + // https://github.com/grpc/grpc/blob/4b05dc88b724214d0c725c8e7442cbc7a61b1374/doc/PROTOCOL-HTTP2.md + // This means printable ASCII (including/plus spaces); 0x20 to 0x7E inclusive. + bytes := []byte(textValue) // gRPC validates strings on the byte level, not Unicode. + for _, ch := range bytes { + if ch < 0x20 || ch > 0x7E { + return false + } + } + return true +} + +//func annotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, metadata.MD, error) { +// ctx = withRPCMethod(ctx, rpcMethodName) +// for _, o := range options { +// ctx = o(ctx) +// } +// timeout := DefaultContextTimeout +// if tm := req.Header.Get(metadataGrpcTimeout); tm != "" { +// var err error +// timeout, err = timeoutDecode(tm) +// if err != nil { +// return nil, nil, status.Errorf(codes.InvalidArgument, "invalid grpc-timeout: %s", tm) +// } +// } +// var pairs []string +// for key, vals := range req.Header { +// key = textproto.CanonicalMIMEHeaderKey(key) +// for _, val := range vals { +// // For backwards-compatibility, pass through 'authorization' header with no prefix. +// if key == "Authorization" { +// pairs = append(pairs, "authorization", val) +// } +// if h, ok := mux.incomingHeaderMatcher(key); ok { +// if !isValidGRPCMetadataKey(h) { +// grpclog.Errorf("HTTP header name %q is not valid as gRPC metadata key; skipping", h) +// continue +// } +// // Handles "-bin" metadata in grpc, since grpc will do another base64 +// // encode before sending to server, we need to decode it first. +// if strings.HasSuffix(key, metadataHeaderBinarySuffix) { +// b, err := decodeBinHeader(val) +// if err != nil { +// return nil, nil, status.Errorf(codes.InvalidArgument, "invalid binary header %s: %s", key, err) +// } +// +// val = string(b) +// } else if !isValidGRPCMetadataTextValue(val) { +// grpclog.Errorf("Value of HTTP header %q contains non-ASCII value (not valid as gRPC metadata): skipping", h) +// continue +// } +// pairs = append(pairs, h, val) +// } +// } +// } +// if host := req.Header.Get(xForwardedHost); host != "" { +// pairs = append(pairs, strings.ToLower(xForwardedHost), host) +// } else if req.Host != "" { +// pairs = append(pairs, strings.ToLower(xForwardedHost), req.Host) +// } +// +// if addr := req.RemoteAddr; addr != "" { +// if remoteIP, _, err := net.SplitHostPort(addr); err == nil { +// if fwd := req.Header.Get(xForwardedFor); fwd == "" { +// pairs = append(pairs, strings.ToLower(xForwardedFor), remoteIP) +// } else { +// pairs = append(pairs, strings.ToLower(xForwardedFor), fmt.Sprintf("%s, %s", fwd, remoteIP)) +// } +// } +// } +// +// if timeout != 0 { +// //nolint:govet // The context outlives this function +// ctx, _ = context.WithTimeout(ctx, timeout) +// } +// if len(pairs) == 0 { +// return ctx, nil, nil +// } +// md := metadata.Pairs(pairs...) +// for _, mda := range mux.metadataAnnotators { +// md = metadata.Join(md, mda(ctx, req)) +// } +// return ctx, md, nil +//} + +// ServerMetadata consists of metadata sent from gRPC server. +type ServerMetadata struct { + HeaderMD metadata.MD + TrailerMD metadata.MD +} + +type serverMetadataKey struct{} + +// NewServerMetadataContext creates a new context with ServerMetadata +func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context { + if ctx == nil { + ctx = context.Background() + } + return context.WithValue(ctx, serverMetadataKey{}, md) +} + +// ServerMetadataFromContext returns the ServerMetadata in ctx +func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool) { + if ctx == nil { + return md, false + } + md, ok = ctx.Value(serverMetadataKey{}).(ServerMetadata) + return +} + +// ServerTransportStream implements grpc.ServerTransportStream. +// It should only be used by the generated files to support grpc.SendHeader +// outside of gRPC server use. +type ServerTransportStream struct { + mu sync.Mutex + header metadata.MD + trailer metadata.MD +} + +// Method returns the method for the stream. +func (s *ServerTransportStream) Method() string { + return "" +} + +// Header returns the header metadata of the stream. +func (s *ServerTransportStream) Header() metadata.MD { + s.mu.Lock() + defer s.mu.Unlock() + return s.header.Copy() +} + +// SetHeader sets the header metadata. +func (s *ServerTransportStream) SetHeader(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + + s.mu.Lock() + s.header = metadata.Join(s.header, md) + s.mu.Unlock() + return nil +} + +// SendHeader sets the header metadata. +func (s *ServerTransportStream) SendHeader(md metadata.MD) error { + return s.SetHeader(md) +} + +// Trailer returns the cached trailer metadata. +func (s *ServerTransportStream) Trailer() metadata.MD { + s.mu.Lock() + defer s.mu.Unlock() + return s.trailer.Copy() +} + +// SetTrailer sets the trailer metadata. +func (s *ServerTransportStream) SetTrailer(md metadata.MD) error { + if md.Len() == 0 { + return nil + } + + s.mu.Lock() + s.trailer = metadata.Join(s.trailer, md) + s.mu.Unlock() + return nil +} + +func timeoutDecode(s string) (time.Duration, error) { + size := len(s) + if size < 2 { + return 0, fmt.Errorf("timeout string is too short: %q", s) + } + d, ok := timeoutUnitToDuration(s[size-1]) + if !ok { + return 0, fmt.Errorf("timeout unit is not recognized: %q", s) + } + t, err := strconv.ParseInt(s[:size-1], 10, 64) + if err != nil { + return 0, err + } + return d * time.Duration(t), nil +} + +func timeoutUnitToDuration(u uint8) (d time.Duration, ok bool) { + switch u { + case 'H': + return time.Hour, true + case 'M': + return time.Minute, true + case 'S': + return time.Second, true + case 'm': + return time.Millisecond, true + case 'u': + return time.Microsecond, true + case 'n': + return time.Nanosecond, true + default: + return + } +} + +// isPermanentHTTPHeader checks whether hdr belongs to the list of +// permanent request headers maintained by IANA. +// http://www.iana.org/assignments/message-headers/message-headers.xml +func isPermanentHTTPHeader(hdr string) bool { + switch hdr { + case + "Accept", + "Accept-Charset", + "Accept-Language", + "Accept-Ranges", + "Authorization", + "Cache-Control", + "Content-Type", + "Cookie", + "Date", + "Expect", + "From", + "Host", + "If-Match", + "If-Modified-Since", + "If-None-Match", + "If-Schedule-Tag-Match", + "If-Unmodified-Since", + "Max-Forwards", + "Origin", + "Pragma", + "Referer", + "User-Agent", + "Via", + "Warning": + return true + } + return false +} + +// isMalformedHTTPHeader checks whether header belongs to the list of +// "malformed headers" and would be rejected by the gRPC server. +func isMalformedHTTPHeader(header string) bool { + _, isMalformed := malformedHTTPHeaders[strings.ToLower(header)] + return isMalformed +} + +// RPCMethod returns the method string for the server context. The returned +// string is in the format of "/package.service/method". +func RPCMethod(ctx context.Context) (string, bool) { + m := ctx.Value(rpcMethodKey{}) + if m == nil { + return "", false + } + ms, ok := m.(string) + if !ok { + return "", false + } + return ms, true +} + +func withRPCMethod(ctx context.Context, rpcMethodName string) context.Context { + return context.WithValue(ctx, rpcMethodKey{}, rpcMethodName) +} + +// HTTPPathPattern returns the HTTP path pattern string relating to the HTTP handler, if one exists. +// The format of the returned string is defined by the google.api.http path template type. +func HTTPPathPattern(ctx context.Context) (string, bool) { + m := ctx.Value(httpPathPatternKey{}) + if m == nil { + return "", false + } + ms, ok := m.(string) + if !ok { + return "", false + } + return ms, true +} + +func withHTTPPathPattern(ctx context.Context, httpPathPattern string) context.Context { + return context.WithValue(ctx, httpPathPatternKey{}, httpPathPattern) +} diff --git a/pkg/gateway/mux.go b/pkg/gateway/mux.go index 591c0721..1ab11693 100644 --- a/pkg/gateway/mux.go +++ b/pkg/gateway/mux.go @@ -14,7 +14,6 @@ import ( "github.com/fullstorydev/grpchan/inprocgrpc" "github.com/gofiber/adaptor/v2" "github.com/gofiber/fiber/v2" - _ "github.com/mwitkow/grpc-proxy/proxy" "github.com/pubgo/funk/assert" "github.com/pubgo/funk/errors" "github.com/pubgo/funk/generic" @@ -24,6 +23,7 @@ import ( "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/gateway/internal/routertree" "github.com/pubgo/lava/pkg/httputil" + "github.com/samber/lo" "google.golang.org/grpc" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" @@ -34,8 +34,6 @@ import ( type muxOptions struct { types protoregistry.MessageTypeResolver files *protoregistry.Files - unaryInterceptor grpc.UnaryServerInterceptor - streamInterceptor grpc.StreamServerInterceptor codecs map[string]Codec codecsByName map[string]Codec compressors map[string]Compressor @@ -162,14 +160,6 @@ func (m *Mux) GetOperationByName(name string) *GrpcMethod { return handleOperation(act) } -func (m *Mux) HandleStream(operation string, stream grpc.ServerStream) error { - mth := m.opts.handlers[operation] - if mth == nil { - return errors.Format("grpc method not found, method=%s", operation) - } - return errors.WrapCaller(mth.Handle(stream)) -} - func (m *Mux) GetOperation(operation string) *GrpcMethod { var opt = m.opts.handlers[operation] if opt == nil { @@ -185,12 +175,6 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { return errors.WrapCaller(err) } - defer func() { - ctx.Response().Header.Set(httputil.HeaderXRequestID, lava.GetReqID(ctx.Context())) - ctx.Response().Header.Set(httputil.HeaderXRequestVersion, version.Version()) - ctx.Response().Header.Set(httputil.HeaderXRequestOperation, matchOperation.Operation) - }() - values := make(url.Values) for _, v := range matchOperation.Vars { values.Set(strings.Join(v.Fields, "."), v.Value) @@ -210,14 +194,50 @@ func (m *Mux) Handler(ctx *fiber.Ctx) error { md.Append(k, v...) } - rspCtx := metadata.NewIncomingContext(ctx.Context(), md) - return errors.WrapCaller(mth.Handle(&streamHTTP{ + stream := &streamHTTP{ handler: ctx, - ctx: rspCtx, + ctx: metadata.NewIncomingContext(ctx.Context(), md), method: mth, params: values, path: matchOperation, - })) + } + + var in = mth.inputType.New().Interface() + err = stream.RecvMsg(in) + if err != nil { + return errors.WrapCaller(err) + } + + var out = mth.outputType.New().Interface() + var header metadata.MD + var trailer metadata.MD + err = m.Invoke(stream.ctx, mth.grpcFullMethod, in, out, grpc.Header(&header), grpc.Trailer(&trailer)) + if err != nil { + return errors.WrapCaller(err) + } + + var hh = make(metadata.MD) + for k, v := range header { + hh.Set(k, v...) + } + + for k, v := range trailer { + hh.Set(k, v...) + } + + for k, v := range hh { + v = lo.Filter(v, func(item string, index int) bool { return item != "" }) + if len(v) == 0 { + continue + } + + ctx.Response().Header.Set(k, v[0]) + } + + ctx.Response().Header.Set(httputil.HeaderXRequestVersion, version.Version()) + ctx.Response().Header.Set(httputil.HeaderXRequestOperation, matchOperation.Operation) + ctx.Response().Header.SetContentTypeBytes(ctx.Request().Header.ContentType()) + return errors.WrapCaller(stream.SendMsg(out)) } func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts ...grpc.CallOption) error { @@ -297,19 +317,18 @@ func NewMux(opts ...MuxOption) *Mux { } func (m *Mux) SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) { - m.opts.unaryInterceptor = interceptor m.localClient.WithServerUnaryInterceptor(interceptor) } // SetStreamInterceptor configures the in-process channel to use the // given server interceptor for streaming RPCs when dispatching. func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor) { - m.opts.streamInterceptor = interceptor m.localClient.WithServerStreamInterceptor(interceptor) } -func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcProxy) { - if err := m.registerService(sd, proxy); err != nil { +func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcRouter, cli grpc.ClientConnInterface) { + assert.If(cli == nil, "cli is nil") + if err := m.registerService(sd, proxy, cli); err != nil { log.Fatal().Err(err).Msgf("gateway: RegisterProxy error: %v", err) } } @@ -326,7 +345,7 @@ func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { log.Fatal().Msgf("gateway: RegisterService found the handler of type %v that does not satisfy %v", st, ht) } - if err := m.registerService(sd, ss); err != nil { + if err := m.registerService(sd, ss, nil); err != nil { log.Fatal().Err(err).Msgf("gateway: RegisterService error: %v", err) } } @@ -340,16 +359,6 @@ func (m *Mux) registerRouter(rule *methodWrapper) { rule.inputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Input().FullName())) rule.outputType = assert.Must1(protoregistry.GlobalTypes.FindMessageByName(rule.grpcMethodProtoDesc.Output().FullName())) - if rule.srv.remoteProxyCli != nil { - if rule.grpcMethodDesc != nil { - rule.grpcMethodDesc.Handler = grpcMethodHandlerWrapper(rule) - } - - if rule.grpcStreamDesc != nil { - rule.grpcStreamDesc.Handler = grpcMethodStreamWrapper(rule) - } - } - assert.Exit(m.routerTree.Add( http.MethodPost, rule.grpcFullMethod, @@ -358,7 +367,7 @@ func (m *Mux) registerRouter(rule *methodWrapper) { ) } -func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { +func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}, cli grpc.ClientConnInterface) error { d, err := m.opts.files.FindDescriptorByName(protoreflect.FullName(gsd.ServiceName)) if err != nil { return errors.WrapCaller(err) @@ -370,14 +379,11 @@ func (m *Mux) registerService(gsd *grpc.ServiceDesc, ss interface{}) error { } srv := &serviceWrapper{ - opts: m.opts, - srv: ss, - serviceDesc: gsd, - servicePbDesc: sd, - } - - if p, ok := ss.(lava.GrpcProxy); ok && p != nil { - srv.remoteProxyCli = p.Proxy() + opts: m.opts, + srv: ss, + serviceDesc: gsd, + servicePbDesc: sd, + remoteProxyCli: cli, } findMethodDesc := func(methodName string) protoreflect.MethodDescriptor { diff --git a/pkg/gateway/stream_http.go b/pkg/gateway/stream_http.go index 27afecc8..229b9a98 100644 --- a/pkg/gateway/stream_http.go +++ b/pkg/gateway/stream_http.go @@ -2,6 +2,7 @@ package gateway import ( "context" + "encoding/json" "fmt" "net/http" "net/url" @@ -132,10 +133,21 @@ func (s *streamHTTP) RecvMsg(m interface{}) error { } } - if len(s.handler.Body()) > 0 { - if err := protojson.Unmarshal(s.handler.Body(), msg); err != nil { + if s.handler.Request().IsBodyStream() { + var b json.RawMessage + if err := json.NewDecoder(s.handler.Request().BodyStream()).Decode(&b); err != nil { + return errors.WrapCaller(err) + } + + if err := protojson.Unmarshal(b, msg); err != nil { return errors.Wrapf(err, "failed to unmarshal body by proto-json, msg=%#v", msg) } + } else { + if body := s.handler.Body(); len(body) > 0 { + if err := protojson.Unmarshal(body, msg); err != nil { + return errors.Wrapf(err, "failed to unmarshal body by proto-json, msg=%#v", msg) + } + } } } diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index 5927d7bb..88053e1e 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -2,6 +2,7 @@ package gateway import ( "context" + "github.com/pubgo/funk/errors" "github.com/pubgo/lava/pkg/proto/lavapbv1" "google.golang.org/grpc" @@ -42,32 +43,32 @@ type methodWrapper struct { meta *lavapbv1.RpcMeta } -func (h methodWrapper) Handle(stream grpc.ServerStream) error { - if h.grpcMethodDesc != nil { - ctx := stream.Context() - - reply, err := h.grpcMethodDesc.Handler(h.srv.srv, ctx, stream.RecvMsg, h.srv.opts.unaryInterceptor) - if err != nil { - return errors.WrapCaller(err) - } - - return errors.WrapCaller(stream.SendMsg(reply)) - } else if h.grpcStreamDesc != nil { - info := &grpc.StreamServerInfo{ - FullMethod: h.grpcFullMethod, - IsClientStream: h.grpcStreamDesc.ClientStreams, - IsServerStream: h.grpcStreamDesc.ServerStreams, - } - - if h.srv.opts.streamInterceptor != nil { - return errors.WrapCaller(h.srv.opts.streamInterceptor(h.srv.srv, stream, info, h.grpcStreamDesc.Handler)) - } else { - return errors.WrapCaller(h.grpcStreamDesc.Handler(h.srv.srv, stream)) - } - } else { - return errors.Format("cannot find server handler") - } -} +//func (h methodWrapper) Handle(stream grpc.ServerStream) error { +// if h.grpcMethodDesc != nil { +// ctx := stream.Context() +// +// reply, err := h.grpcMethodDesc.Handler(h.srv.srv, ctx, stream.RecvMsg, h.srv.opts.unaryInterceptor) +// if err != nil { +// return errors.WrapCaller(err) +// } +// +// return errors.WrapCaller(stream.SendMsg(reply)) +// } else if h.grpcStreamDesc != nil { +// info := &grpc.StreamServerInfo{ +// FullMethod: h.grpcFullMethod, +// IsClientStream: h.grpcStreamDesc.ClientStreams, +// IsServerStream: h.grpcStreamDesc.ServerStreams, +// } +// +// if h.srv.opts.streamInterceptor != nil { +// return errors.WrapCaller(h.srv.opts.streamInterceptor(h.srv.srv, stream, info, h.grpcStreamDesc.Handler)) +// } else { +// return errors.WrapCaller(h.grpcStreamDesc.Handler(h.srv.srv, stream)) +// } +// } else { +// return errors.Format("cannot find server handler") +// } +//} func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcMethodHandler { return func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) { @@ -78,7 +79,7 @@ func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcM var h = func(ctx context.Context, req any) (any, error) { var out = mth.outputType.New().Interface() - err := mth.srv.remoteProxyCli.Invoke(ctx, mth.grpcFullMethod, in, out, opts...) + err := mth.srv.remoteProxyCli.Invoke(ctx, mth.grpcFullMethod, req, out, opts...) if err != nil { return nil, err } diff --git a/servers/grpcs/inner_server.go b/servers/grpcs/inner_server.go index 796d5537..b15df4d7 100644 --- a/servers/grpcs/inner_server.go +++ b/servers/grpcs/inner_server.go @@ -1,9 +1,15 @@ package grpcs import ( + "context" + "fmt" + "github.com/fullstorydev/grpchan/inprocgrpc" "github.com/pubgo/funk/assert" + "github.com/pubgo/funk/errors" "github.com/pubgo/funk/log" + "github.com/pubgo/lava/clients/grpcc" + "github.com/pubgo/lava/clients/grpcc/grpcc_config" "github.com/pubgo/lava/core/metrics" "github.com/pubgo/lava/internal/middlewares/middleware_accesslog" "github.com/pubgo/lava/internal/middlewares/middleware_metric" @@ -11,10 +17,14 @@ import ( "github.com/pubgo/lava/internal/middlewares/middleware_service_info" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/gateway" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" ) // NewInner grpc 服务内部通信 -func NewInner(handlers []lava.GrpcRouter, dixMiddlewares []lava.Middleware, metric metrics.Metric, log log.Logger) *lava.InnerServer { +func NewInner(handlers []lava.GrpcRouter, grpcProxy []lava.GrpcProxy, dixMiddlewares []lava.Middleware, metric metrics.Metric, log log.Logger) *lava.InnerServer { middlewares := lava.Middlewares{ middleware_service_info.New(), middleware_metric.New(metric), @@ -34,6 +44,36 @@ func NewInner(handlers []lava.GrpcRouter, dixMiddlewares []lava.Middleware, metr cc.RegisterService(h.ServiceDesc(), h) } + for _, h := range grpcProxy { + desc := h.ServiceDesc() + assert.If(desc == nil, "desc is nil") + + srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], middlewares...) + srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], h.Middlewares()...) + + cli := grpcc.New( + &grpcc_config.Cfg{ + Service: &grpcc_config.ServiceCfg{ + Name: h.Proxy().Name, + Addr: h.Proxy().Addr, + Scheme: h.Proxy().Resolver, + }, + }, + grpcc.Params{ + Log: log, + Metric: metric, + }, + srvMidMap[desc.ServiceName]..., + ) + + for i := range desc.Methods { + var fullPath = fmt.Sprintf("/%s/%s", desc.ServiceName, desc.Methods[i].MethodName) + inT, outT := getMthType(desc.ServiceName, desc.Methods[i].MethodName) + desc.Methods[i].Handler = grpcMethodHandlerWrapper(cli, fullPath, inT, outT) + } + cc.RegisterService(h.ServiceDesc(), h) + } + cc = cc.WithServerUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) cc = cc.WithServerStreamInterceptor(handlerStreamMiddle(srvMidMap)) return &lava.InnerServer{ClientConnInterface: cc} @@ -63,3 +103,51 @@ func NewMux(handlers []lava.GrpcRouter, dixMiddlewares []lava.Middleware, metric mux.SetStreamInterceptor(handlerStreamMiddle(srvMidMap)) return mux } + +func grpcMethodHandlerWrapper(cli grpc.ClientConnInterface, fullPath string, inType, outType protoreflect.MessageType) gateway.GrpcMethodHandler { + return func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) { + var in = inType.New().Interface() + if err := dec(in); err != nil { + return nil, errors.WrapCaller(err) + } + + var h = func(ctx context.Context, req any) (any, error) { + var out = outType.New().Interface() + var header metadata.MD + var trailer metadata.MD + err := cli.Invoke(ctx, fullPath, req, out, append([]grpc.CallOption{}, grpc.Header(&header), grpc.Trailer(&trailer))...) + if err != nil { + return nil, err + } + return out, nil + } + + // 获取 server header 并转换成 client header + if interceptor == nil { + return h(ctx, in) + } + + return interceptor(ctx, in, &grpc.UnaryServerInfo{FullMethod: fullPath}, h) + } +} + +func getMthType(srvName string, mthName string) (protoreflect.MessageType, protoreflect.MessageType) { + d := assert.Must1(protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(srvName))) + + sd, ok := d.(protoreflect.ServiceDescriptor) + if !ok { + assert.Must(errors.Format("invalid httpPathRule descriptor %T", d)) + } + + findMethodDesc := func(methodName string) protoreflect.MethodDescriptor { + md := sd.Methods().ByName(protoreflect.Name(methodName)) + assert.If(md == nil, "missing protobuf descriptor for %v", methodName) + return md + } + + mthDesc := findMethodDesc(mthName) + + inputType := assert.Must1(protoregistry.GlobalTypes.FindMessageByName(mthDesc.Input().FullName())) + outputType := assert.Must1(protoregistry.GlobalTypes.FindMessageByName(mthDesc.Output().FullName())) + return inputType, outputType +} diff --git a/servers/grpcs/middleware.go b/servers/grpcs/middleware.go index 4d1b03d8..ba6c7fd2 100644 --- a/servers/grpcs/middleware.go +++ b/servers/grpcs/middleware.go @@ -123,12 +123,13 @@ func handlerUnaryMiddle(middlewares map[string][]lava.Middleware) grpc.UnaryServ }) if err := grpc.SetHeader(ctx, reqMetadata); err != nil { - log.Err(err, ctx).Msg("grpc set trailer failed") + log.Err(err, ctx).Msg("grpc send trailer failed") } if err := grpc.SendHeader(ctx, reqMetadata); err != nil { log.Err(err, ctx).Msg("grpc send trailer failed") } + }() ctx = lava.CreateReqHeader(ctx, reqHeader) diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index b88dcb9f..efc58ba1 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -27,6 +27,8 @@ import ( "github.com/pubgo/funk/stack" "github.com/pubgo/funk/vars" "github.com/pubgo/funk/version" + "github.com/pubgo/lava/clients/grpcc" + "github.com/pubgo/lava/clients/grpcc/grpcc_config" "github.com/pubgo/lava/core/debug" "github.com/pubgo/lava/core/lifecycle" "github.com/pubgo/lava/core/metrics" @@ -156,10 +158,10 @@ func (s *serviceImpl) DixInject( fiber.MethodHead, fiber.MethodOptions, }, ","), - AllowHeaders: "", + //AllowHeaders: "", AllowCredentials: true, - ExposeHeaders: "", - MaxAge: 0, + //ExposeHeaders: "", + MaxAge: 0, })) } @@ -370,7 +372,23 @@ func (s *serviceImpl) DixInject( s.initList = append(s.initList, m.Init) } - mux.RegisterProxy(desc, h) + mux.RegisterProxy( + desc, h, + grpcc.New( + &grpcc_config.Cfg{ + Service: &grpcc_config.ServiceCfg{ + Name: h.Proxy().Name, + Addr: h.Proxy().Addr, + Scheme: h.Proxy().Resolver, + }, + }, + grpcc.Params{ + Log: log, + Metric: metric, + }, + srvMidMap[desc.ServiceName]..., + ), + ) } mux.SetUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) diff --git a/services/metadata/service.go b/services/metadataservice/service.go similarity index 99% rename from services/metadata/service.go rename to services/metadataservice/service.go index ee861324..c4f714e1 100644 --- a/services/metadata/service.go +++ b/services/metadataservice/service.go @@ -1,4 +1,4 @@ -package metadata +package metadataservice import ( "bytes" From 19c54752d18bf599cda2e25ac85a195cde11d1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 13:43:46 +0800 Subject: [PATCH 32/41] fix: barry 2024-07-26 13:43:46 --- .../handlers/gid_handler/handler_proxy.go | 1 + pkg/gateway/stream_proxy.go | 36 ++++++++----------- pkg/gateway/wrapper.go | 6 ---- servers/grpcs/inner_server.go | 34 +++++------------- servers/grpcs/server.go | 34 ++++++++++-------- 5 files changed, 43 insertions(+), 68 deletions(-) diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go index ecdb6995..3b267e15 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go @@ -18,6 +18,7 @@ func NewIdProxy() lava.GrpcProxy { } type IdProxy struct { + gidpb.IdProxyServer } func (i IdProxy) Middlewares() []lava.Middleware { diff --git a/pkg/gateway/stream_proxy.go b/pkg/gateway/stream_proxy.go index f471fcfa..74404ce2 100644 --- a/pkg/gateway/stream_proxy.go +++ b/pkg/gateway/stream_proxy.go @@ -11,7 +11,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "google.golang.org/protobuf/types/known/emptypb" + "google.golang.org/protobuf/reflect/protoreflect" ) var ( @@ -21,17 +21,15 @@ var ( } ) -// TransparentHandler returns a handler that attempts to proxy all requests that are not registered in the server. -// The indented use here is as a transparent proxy, where the server doesn't know about the services implemented by the -// backends. It should be used as a `grpc.UnknownServiceHandler`. -func TransparentHandler(director StreamDirector, opts ...grpc.CallOption) grpc.StreamHandler { - streamer := &handler{director: director, opts: opts} +func TransparentHandler(cli grpc.ClientConnInterface, inType, outType protoreflect.MessageType, opts ...grpc.CallOption) grpc.StreamHandler { + streamer := &handler{cli: cli, opts: opts, inType: inType, outType: outType} return streamer.handler } type handler struct { - director StreamDirector - opts []grpc.CallOption + cli grpc.ClientConnInterface + inType, outType protoreflect.MessageType + opts []grpc.CallOption } // handler is where the real magic of proxying happens. @@ -44,15 +42,9 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error return status.Errorf(codes.Internal, "lowLevelServerStream not exists in context") } - // We require that the director's returned context inherits from the serverStream.Context(). - outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName) - if err != nil { - return errors.WrapCaller(err) - } - - clientCtx, clientCancel := context.WithCancel(outgoingCtx) + clientCtx, clientCancel := context.WithCancel(serverStream.Context()) defer clientCancel() - clientStream, err := backendConn.NewStream(clientCtx, clientStreamDescForProxying, fullMethodName, s.opts...) + clientStream, err := s.cli.NewStream(clientCtx, clientStreamDescForProxying, fullMethodName, s.opts...) if err != nil { return errors.WrapCaller(err) } @@ -60,8 +52,8 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error // Explicitly *do not close* s2cErrChan and c2sErrChan, otherwise the select below will not terminate. // Channels do not have to be closed, it is just a control flow mechanism, see // https://groups.google.com/forum/#!msg/golang-nuts/pZwdYRGxCIk/qpbHxRRPJdUJ - s2cErrChan := s.forwardServerToClient(serverStream, clientStream) - c2sErrChan := s.forwardClientToServer(clientStream, serverStream) + s2cErrChan := forwardServerToClient(s.inType, serverStream, clientStream) + c2sErrChan := forwardClientToServer(s.outType, clientStream, serverStream) // We don't know which side is going to stop sending first, so we need a select between the two. for i := 0; i < 2; i++ { select { @@ -92,10 +84,10 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error return status.Errorf(codes.Internal, "gRPC proxying should never reach this stage.") } -func (s *handler) forwardClientToServer(src grpc.ClientStream, dst grpc.ServerStream) chan error { +func forwardClientToServer(out protoreflect.MessageType, src grpc.ClientStream, dst grpc.ServerStream) chan error { ret := make(chan error, 1) go func() { - f := &emptypb.Empty{} + f := out.New().Interface() for i := 0; ; i++ { if err := src.RecvMsg(f); err != nil { ret <- err // this can be io.EOF which is happy case @@ -124,10 +116,10 @@ func (s *handler) forwardClientToServer(src grpc.ClientStream, dst grpc.ServerSt return ret } -func (s *handler) forwardServerToClient(src grpc.ServerStream, dst grpc.ClientStream) chan error { +func forwardServerToClient(in protoreflect.MessageType, src grpc.ServerStream, dst grpc.ClientStream) chan error { ret := make(chan error, 1) go func() { - f := &emptypb.Empty{} + f := in.New().Interface() for i := 0; ; i++ { if err := src.RecvMsg(f); err != nil { ret <- err // this can be io.EOF which is happy case diff --git a/pkg/gateway/wrapper.go b/pkg/gateway/wrapper.go index 88053e1e..aa55fdfd 100644 --- a/pkg/gateway/wrapper.go +++ b/pkg/gateway/wrapper.go @@ -94,9 +94,3 @@ func grpcMethodHandlerWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcM return interceptor(ctx, in, &grpc.UnaryServerInfo{FullMethod: mth.grpcFullMethod}, h) } } - -func grpcMethodStreamWrapper(mth *methodWrapper, opts ...grpc.CallOption) GrpcStreamHandler { - return TransparentHandler(func(ctx context.Context, fullMethodName string) (context.Context, grpc.ClientConnInterface, error) { - return ctx, mth.srv.remoteProxyCli, nil - }, opts...) -} diff --git a/servers/grpcs/inner_server.go b/servers/grpcs/inner_server.go index b15df4d7..b127b270 100644 --- a/servers/grpcs/inner_server.go +++ b/servers/grpcs/inner_server.go @@ -71,6 +71,11 @@ func NewInner(handlers []lava.GrpcRouter, grpcProxy []lava.GrpcProxy, dixMiddlew inT, outT := getMthType(desc.ServiceName, desc.Methods[i].MethodName) desc.Methods[i].Handler = grpcMethodHandlerWrapper(cli, fullPath, inT, outT) } + + for i := range desc.Streams { + inT, outT := getMthType(desc.ServiceName, desc.Methods[i].MethodName) + desc.Streams[i].Handler = grpcMethodStreamWrapper(cli, inT, outT) + } cc.RegisterService(h.ServiceDesc(), h) } @@ -79,31 +84,6 @@ func NewInner(handlers []lava.GrpcRouter, grpcProxy []lava.GrpcProxy, dixMiddlew return &lava.InnerServer{ClientConnInterface: cc} } -func NewMux(handlers []lava.GrpcRouter, dixMiddlewares []lava.Middleware, metric metrics.Metric, log log.Logger) *gateway.Mux { - middlewares := lava.Middlewares{ - middleware_service_info.New(), - middleware_metric.New(metric), - middleware_accesslog.New(log), - middleware_recovery.New(), - } - middlewares = append(middlewares, dixMiddlewares...) - - mux := gateway.NewMux() - srvMidMap := make(map[string][]lava.Middleware) - for _, h := range handlers { - desc := h.ServiceDesc() - assert.If(desc == nil, "desc is nil") - - srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], middlewares...) - srvMidMap[desc.ServiceName] = append(srvMidMap[desc.ServiceName], h.Middlewares()...) - mux.RegisterService(desc, h) - } - - mux.SetUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) - mux.SetStreamInterceptor(handlerStreamMiddle(srvMidMap)) - return mux -} - func grpcMethodHandlerWrapper(cli grpc.ClientConnInterface, fullPath string, inType, outType protoreflect.MessageType) gateway.GrpcMethodHandler { return func(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) { var in = inType.New().Interface() @@ -151,3 +131,7 @@ func getMthType(srvName string, mthName string) (protoreflect.MessageType, proto outputType := assert.Must1(protoregistry.GlobalTypes.FindMessageByName(mthDesc.Output().FullName())) return inputType, outputType } + +func grpcMethodStreamWrapper(cli grpc.ClientConnInterface, inType, outType protoreflect.MessageType) gateway.GrpcStreamHandler { + return gateway.TransparentHandler(cli, inType, outType) +} diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index efc58ba1..b0b135cb 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -372,23 +372,27 @@ func (s *serviceImpl) DixInject( s.initList = append(s.initList, m.Init) } - mux.RegisterProxy( - desc, h, - grpcc.New( - &grpcc_config.Cfg{ - Service: &grpcc_config.ServiceCfg{ - Name: h.Proxy().Name, - Addr: h.Proxy().Addr, - Scheme: h.Proxy().Resolver, - }, + cli := grpcc.New( + &grpcc_config.Cfg{ + Service: &grpcc_config.ServiceCfg{ + Name: h.Proxy().Name, + Addr: h.Proxy().Addr, + Scheme: h.Proxy().Resolver, }, - grpcc.Params{ - Log: log, - Metric: metric, - }, - srvMidMap[desc.ServiceName]..., - ), + }, + grpcc.Params{ + Log: log, + Metric: metric, + }, + srvMidMap[desc.ServiceName]..., ) + + for i := range desc.Methods { + var fullPath = fmt.Sprintf("/%s/%s", desc.ServiceName, desc.Methods[i].MethodName) + inT, outT := getMthType(desc.ServiceName, desc.Methods[i].MethodName) + desc.Methods[i].Handler = grpcMethodHandlerWrapper(cli, fullPath, inT, outT) + } + mux.RegisterService(desc, h) } mux.SetUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) From fffd89e3afa74ed0c73486926eefe463fb84bfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 23:36:29 +0800 Subject: [PATCH 33/41] fix: barry 2024-07-26 23:36:29 --- clients/grpcc/client.go | 14 +- clients/grpcc/grpcc_resolver/register.go | 4 +- internal/example/grpc/docs/api.http | 5 +- .../example/grpc/internal/bootstrap/boot.go | 4 + .../handlers/gid_handler/handler_grpc.go | 14 +- .../handlers/gid_handler/handler_proxy.go | 2 + .../gid_handler/handler_proxy_server.go | 1 + internal/example/grpc/openapi.yaml | 15 + .../example/grpc/pkg/proto/gidpb/id.pb.go | 313 +++++++++++------- .../grpc/pkg/proto/gidpb/id_grpc.pb.go | 37 +++ internal/example/grpc/proto/gid/id.proto | 11 +- .../middleware_accesslog/middleware.go | 3 +- .../middleware_service_info/middleware.go | 2 +- pkg/grpcutil/util.go | 10 +- servers/grpcs/inner_server.go | 4 +- servers/grpcs/server.go | 24 +- 16 files changed, 289 insertions(+), 174 deletions(-) diff --git a/clients/grpcc/client.go b/clients/grpcc/client.go index 82a8360f..5e548aef 100644 --- a/clients/grpcc/client.go +++ b/clients/grpcc/client.go @@ -13,10 +13,6 @@ import ( "github.com/pubgo/funk/vars" "github.com/pubgo/lava/clients/grpcc/grpcc_config" "github.com/pubgo/lava/core/metrics" - "github.com/pubgo/lava/internal/middlewares/middleware_accesslog" - "github.com/pubgo/lava/internal/middlewares/middleware_metric" - "github.com/pubgo/lava/internal/middlewares/middleware_recovery" - "github.com/pubgo/lava/internal/middlewares/middleware_service_info" "github.com/pubgo/lava/lava" "google.golang.org/grpc" "google.golang.org/grpc/health/grpc_health_v1" @@ -33,18 +29,10 @@ func New(cfg *grpcc_config.Cfg, p Params, middlewares ...lava.Middleware) Client cfg = config.MergeR(grpcc_config.DefaultCfg(), cfg).Unwrap() cfg.Resolvers = p.Resolvers - defaultMiddlewares := lava.Middlewares{ - middleware_service_info.New(), - middleware_metric.New(p.Metric), - middleware_accesslog.New(p.Log.WithFields(log.Map{"service": cfg.Service.Name})), - middleware_recovery.New(), - } - defaultMiddlewares = append(defaultMiddlewares, middlewares...) - c := &clientImpl{ cfg: cfg, log: p.Log, - middlewares: defaultMiddlewares, + middlewares: middlewares, } vars.RegisterValue(fmt.Sprintf("%s-grpc-client-config", cfg.Service.Name), cfg) diff --git a/clients/grpcc/grpcc_resolver/register.go b/clients/grpcc/grpcc_resolver/register.go index e1210691..446f39fb 100644 --- a/clients/grpcc/grpcc_resolver/register.go +++ b/clients/grpcc/grpcc_resolver/register.go @@ -1,7 +1,9 @@ package grpcc_resolver +import "google.golang.org/grpc/resolver" + func init() { - // resolver.Register(&directBuilder{}) + resolver.Register(NewDirectBuilder()) // resolver.Register(&discoveryBuilder{}) // resolver.Register(kuberesolver.NewBuilder(nil, "kubernetes")) } diff --git a/internal/example/grpc/docs/api.http b/internal/example/grpc/docs/api.http index 55da651e..df5a93c4 100644 --- a/internal/example/grpc/docs/api.http +++ b/internal/example/grpc/docs/api.http @@ -3,7 +3,10 @@ GET http://localhost:8080/gid/gw/v1/id/types/hello/111 Content-Type: application/json ### +GET http://localhost:8080/gid/gw/proxy/test +Content-Type: application/json +### PUT http://localhost:8080/gid/gw/v1/id/types/hello/111 Content-Type: application/json @@ -12,7 +15,7 @@ Content-Type: application/json } ### proxy -POST http://localhost:8081/gid/gw/v1/id/echo +POST http://localhost:8080/gid/gw/v1/id/echo Content-Type: application/json { diff --git a/internal/example/grpc/internal/bootstrap/boot.go b/internal/example/grpc/internal/bootstrap/boot.go index b65369ec..c523d7d5 100644 --- a/internal/example/grpc/internal/bootstrap/boot.go +++ b/internal/example/grpc/internal/bootstrap/boot.go @@ -7,6 +7,7 @@ import ( "github.com/pubgo/lava/internal/example/grpc/internal/handlers/gid_handler" "github.com/pubgo/lava/internal/example/grpc/internal/services/gid_client" "github.com/pubgo/lava/internal/example/grpc/taskcmd" + "github.com/pubgo/lava/pkg/gateway" ) func Main() { @@ -19,6 +20,9 @@ func Main() { di.Provide(gid_handler.NewHttp) di.Provide(gid_handler.NewHttp111) di.Provide(gid_client.New) + di.Provide(func() *gateway.Mux { + return gateway.NewMux() + }) di.Provide(taskcmd.New) //di.Provide(func() lava.Middleware { // return lava.MiddlewareWrap{ diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go b/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go index 8fffdc9e..1c970a9e 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_grpc.go @@ -3,6 +3,7 @@ package gid_handler import ( "context" "fmt" + "github.com/pubgo/lava/pkg/gateway" "math/rand" "net/http" "time" @@ -40,6 +41,16 @@ type Id struct { bigflake *bigflake.Bigflake log log.Logger service *gid_client.Service + mux *gateway.Mux +} + +func (id *Id) DoProxy(ctx context.Context, empty *gidpb.Empty) (*gidpb.Empty, error) { + rsp, err := gidpb.NewIdProxyClient(id.mux).Echo(ctx, &gidpb.EchoReq{Hello: "hello"}) + if err != nil { + return nil, err + } + fmt.Println(rsp.String()) + return new(gidpb.Empty), nil } func (id *Id) PutTypes(ctx context.Context, req *gidpb.TypesRequest) (*gidpb.TypesResponse, error) { @@ -117,7 +128,7 @@ func (id *Id) ServiceDesc() *grpc.ServiceDesc { return &gidpb.Id_ServiceDesc } -func New(cron *scheduler.Scheduler, metric metrics.Metric, log log.Logger, service *gid_client.Service) lava.GrpcRouter { +func New(cron *scheduler.Scheduler, metric metrics.Metric, log log.Logger, service *gid_client.Service, mux *gateway.Mux) lava.GrpcRouter { id := rand.Intn(100) sf, err := snowflake.New(uint32(id)) @@ -136,6 +147,7 @@ func New(cron *scheduler.Scheduler, metric metrics.Metric, log log.Logger, servi snowflake: sf, bigflake: bg, log: log.WithName("gid"), + mux: mux, } } diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go index 3b267e15..3974ca97 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy.go @@ -27,6 +27,8 @@ func (i IdProxy) Middlewares() []lava.Middleware { Next: func(next lava.HandlerFunc) lava.HandlerFunc { return func(ctx context.Context, req lava.Request) (lava.Response, error) { fmt.Println("proxy-header", req.Header().String()) + + req.Header().Set("inner", "proxy") return next(ctx, req) } }, diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go index 2b29c7a4..111b8195 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go @@ -23,6 +23,7 @@ type IdProxyServer struct { func (i IdProxyServer) Echo(ctx context.Context, req *gidpb.EchoReq) (*gidpb.EchoRsp, error) { fmt.Println("get echo request", req.String()) + fmt.Println("req", lava.ReqHeader(ctx).String()) return &gidpb.EchoRsp{Hello: req.Hello}, nil } diff --git a/internal/example/grpc/openapi.yaml b/internal/example/grpc/openapi.yaml index 542fe415..bc8559f6 100644 --- a/internal/example/grpc/openapi.yaml +++ b/internal/example/grpc/openapi.yaml @@ -30,6 +30,18 @@ paths: description: OK content: '*/*': {} + /proxy/test: + get: + tags: + - Id + operationId: Id_DoProxy + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Empty' /v1/id/echo: post: tags: @@ -201,6 +213,9 @@ components: properties: hello: type: string + Empty: + type: object + properties: {} GenerateRequest: type: object properties: diff --git a/internal/example/grpc/pkg/proto/gidpb/id.pb.go b/internal/example/grpc/pkg/proto/gidpb/id.pb.go index 1a77b48b..a8d1c984 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id.pb.go @@ -184,6 +184,44 @@ func (x *GenerateResponse) GetType() string { return "" } +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_gid_id_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_gid_id_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_gid_id_proto_rawDescGZIP(), []int{1} +} + type UploadFileRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -196,7 +234,7 @@ type UploadFileRequest struct { func (x *UploadFileRequest) Reset() { *x = UploadFileRequest{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[1] + mi := &file_gid_id_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -209,7 +247,7 @@ func (x *UploadFileRequest) String() string { func (*UploadFileRequest) ProtoMessage() {} func (x *UploadFileRequest) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[1] + mi := &file_gid_id_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -222,7 +260,7 @@ func (x *UploadFileRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use UploadFileRequest.ProtoReflect.Descriptor instead. func (*UploadFileRequest) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{1} + return file_gid_id_proto_rawDescGZIP(), []int{2} } func (x *UploadFileRequest) GetFilename() string { @@ -252,7 +290,7 @@ type ChatMessage struct { func (x *ChatMessage) Reset() { *x = ChatMessage{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[2] + mi := &file_gid_id_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -265,7 +303,7 @@ func (x *ChatMessage) String() string { func (*ChatMessage) ProtoMessage() {} func (x *ChatMessage) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[2] + mi := &file_gid_id_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -278,7 +316,7 @@ func (x *ChatMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use ChatMessage.ProtoReflect.Descriptor instead. func (*ChatMessage) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{2} + return file_gid_id_proto_rawDescGZIP(), []int{3} } func (x *ChatMessage) GetName() string { @@ -314,7 +352,7 @@ type Message struct { func (x *Message) Reset() { *x = Message{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[3] + mi := &file_gid_id_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -327,7 +365,7 @@ func (x *Message) String() string { func (*Message) ProtoMessage() {} func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[3] + mi := &file_gid_id_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -340,7 +378,7 @@ func (x *Message) ProtoReflect() protoreflect.Message { // Deprecated: Use Message.ProtoReflect.Descriptor instead. func (*Message) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{3} + return file_gid_id_proto_rawDescGZIP(), []int{4} } func (x *Message) GetName() string { @@ -370,7 +408,7 @@ type GenerateRequest struct { func (x *GenerateRequest) Reset() { *x = GenerateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[4] + mi := &file_gid_id_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -383,7 +421,7 @@ func (x *GenerateRequest) String() string { func (*GenerateRequest) ProtoMessage() {} func (x *GenerateRequest) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[4] + mi := &file_gid_id_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -396,7 +434,7 @@ func (x *GenerateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GenerateRequest.ProtoReflect.Descriptor instead. func (*GenerateRequest) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{4} + return file_gid_id_proto_rawDescGZIP(), []int{5} } func (x *GenerateRequest) GetType() GenType { @@ -420,7 +458,7 @@ type TypesRequest struct { func (x *TypesRequest) Reset() { *x = TypesRequest{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[5] + mi := &file_gid_id_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -433,7 +471,7 @@ func (x *TypesRequest) String() string { func (*TypesRequest) ProtoMessage() {} func (x *TypesRequest) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[5] + mi := &file_gid_id_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -446,7 +484,7 @@ func (x *TypesRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use TypesRequest.ProtoReflect.Descriptor instead. func (*TypesRequest) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{5} + return file_gid_id_proto_rawDescGZIP(), []int{6} } func (x *TypesRequest) GetName() string { @@ -482,7 +520,7 @@ type TypesResponse struct { func (x *TypesResponse) Reset() { *x = TypesResponse{} if protoimpl.UnsafeEnabled { - mi := &file_gid_id_proto_msgTypes[6] + mi := &file_gid_id_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -495,7 +533,7 @@ func (x *TypesResponse) String() string { func (*TypesResponse) ProtoMessage() {} func (x *TypesResponse) ProtoReflect() protoreflect.Message { - mi := &file_gid_id_proto_msgTypes[6] + mi := &file_gid_id_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -508,7 +546,7 @@ func (x *TypesResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use TypesResponse.ProtoReflect.Descriptor instead. func (*TypesResponse) Descriptor() ([]byte, []int) { - return file_gid_id_proto_rawDescGZIP(), []int{6} + return file_gid_id_proto_rawDescGZIP(), []int{7} } func (x *TypesResponse) GetTypes() []string { @@ -535,85 +573,89 @@ var file_gid_id_proto_rawDesc = []byte{ 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, - 0x65, 0x22, 0x59, 0x0a, 0x11, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, - 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x60, 0x0a, 0x0b, - 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1e, - 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x67, 0x69, - 0x64, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x31, - 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, - 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, - 0x74, 0x22, 0x33, 0x0a, 0x0f, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, - 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x51, 0x0a, 0x0c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x61, - 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x61, 0x6d, - 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x25, 0x0a, 0x0d, 0x54, 0x79, 0x70, - 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x79, - 0x70, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x74, 0x79, 0x70, 0x65, 0x73, - 0x2a, 0x37, 0x0a, 0x07, 0x53, 0x72, 0x76, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x4f, - 0x4b, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x10, 0x49, 0x44, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, - 0x65, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x64, 0x1a, 0x06, 0x92, 0xea, 0x30, 0x02, 0x08, - 0x0d, 0x1a, 0x06, 0x8a, 0xea, 0x30, 0x02, 0x08, 0x01, 0x2a, 0x4a, 0x0a, 0x07, 0x47, 0x65, 0x6e, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x10, - 0x00, 0x12, 0x08, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x73, - 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, - 0x67, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x68, 0x6f, 0x72, - 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xa2, 0x05, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x81, 0x01, 0x0a, - 0x08, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, - 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x15, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x48, 0xa2, 0xea, 0x30, 0x2a, 0x0a, 0x06, 0x69, 0x64, - 0x2e, 0x67, 0x65, 0x6e, 0x1a, 0x0e, 0x0a, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x05, 0x77, - 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x10, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x12, 0x04, 0x74, 0x72, 0x75, 0x65, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, - 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, - 0x12, 0x4c, 0x0a, 0x0a, 0x54, 0x79, 0x70, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, - 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, - 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, - 0x0a, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, + 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x59, 0x0a, 0x11, 0x55, 0x70, + 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x66, + 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x52, + 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x60, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x31, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x33, 0x0a, 0x0f, 0x47, 0x65, + 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x67, 0x69, + 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, + 0x51, 0x0a, 0x0c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x68, 0x65, 0x6c, + 0x6c, 0x6f, 0x22, 0x25, 0x0a, 0x0d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x05, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2a, 0x37, 0x0a, 0x07, 0x53, 0x72, 0x76, + 0x43, 0x6f, 0x64, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x10, + 0x49, 0x44, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, + 0x10, 0x64, 0x1a, 0x06, 0x92, 0xea, 0x30, 0x02, 0x08, 0x0d, 0x1a, 0x06, 0x8a, 0xea, 0x30, 0x02, + 0x08, 0x01, 0x2a, 0x4a, 0x0a, 0x07, 0x47, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, + 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x75, 0x75, + 0x69, 0x64, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x73, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, + 0x65, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x67, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x10, + 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x69, 0x64, 0x10, 0x04, 0x32, 0xda, + 0x05, 0x0a, 0x02, 0x49, 0x64, 0x12, 0x81, 0x01, 0x0a, 0x08, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x12, 0x14, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x47, + 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x48, 0xa2, 0xea, 0x30, 0x2a, 0x0a, 0x06, 0x69, 0x64, 0x2e, 0x67, 0x65, 0x6e, 0x1a, 0x0e, 0x0a, + 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x10, 0x0a, + 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x12, 0x04, 0x74, 0x72, 0x75, 0x65, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, + 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x4c, 0x0a, 0x0a, 0x54, 0x79, 0x70, + 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, - 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x12, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, - 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, - 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5b, 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, - 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, - 0x3a, 0x01, 0x2a, 0x1a, 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, - 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, - 0x64, 0x7d, 0x12, 0x6f, 0x0a, 0x04, 0x43, 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, - 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, - 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, - 0xba, 0x47, 0x27, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, - 0x61, 0x67, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, - 0x67, 0x31, 0x12, 0x06, 0xe8, 0x81, 0x8a, 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, - 0x3a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x08, 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, - 0x01, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x05, 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, - 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, - 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, - 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, - 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, - 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, - 0x66, 0x69, 0x6c, 0x65, 0x22, 0x11, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, - 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, 0x61, - 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, - 0x67, 0x69, 0x64, 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x12, 0x0d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x31, 0x30, 0x01, 0x12, 0x55, 0x0a, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, + 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x25, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1f, 0x12, + 0x1d, 0x2f, 0x76, 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, + 0x61, 0x6d, 0x65, 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x5b, + 0x0a, 0x08, 0x50, 0x75, 0x74, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x67, 0x69, 0x64, + 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, + 0x67, 0x69, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x28, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x22, 0x3a, 0x01, 0x2a, 0x1a, 0x1d, 0x2f, 0x76, + 0x31, 0x2f, 0x69, 0x64, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, + 0x7d, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x7d, 0x12, 0x6f, 0x0a, 0x04, 0x43, + 0x68, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3f, 0xba, 0x47, 0x27, 0x0a, 0x0d, 0x63, 0x68, + 0x61, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x0a, 0x0e, 0x63, 0x68, 0x61, + 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x61, 0x67, 0x31, 0x12, 0x06, 0xe8, 0x81, 0x8a, + 0xe5, 0xa4, 0xa9, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0f, 0x3a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x08, + 0x2f, 0x77, 0x73, 0x2f, 0x63, 0x68, 0x61, 0x74, 0x28, 0x01, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x05, + 0x43, 0x68, 0x61, 0x74, 0x31, 0x12, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, 0x61, 0x74, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x10, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x43, 0x68, + 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, + 0x5f, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, + 0x64, 0x12, 0x16, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x46, 0x69, + 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x22, + 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x11, 0x2f, + 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x7b, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x7d, + 0x12, 0x36, 0x0a, 0x07, 0x44, 0x6f, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x0a, 0x2e, 0x67, 0x69, + 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0a, 0x2e, 0x67, 0x69, 0x64, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x70, 0x72, + 0x6f, 0x78, 0x79, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x1a, 0x11, 0xca, 0x41, 0x0e, 0x6c, 0x6f, 0x63, + 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x38, 0x30, 0x38, 0x30, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, + 0x2f, 0x67, 0x69, 0x64, 0x70, 0x62, 0x3b, 0x67, 0x69, 0x64, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -629,39 +671,42 @@ func file_gid_id_proto_rawDescGZIP() []byte { } var file_gid_id_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_gid_id_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_gid_id_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_gid_id_proto_goTypes = []any{ (SrvCode)(0), // 0: gid.SrvCode (GenType)(0), // 1: gid.GenType (*GenerateResponse)(nil), // 2: gid.GenerateResponse - (*UploadFileRequest)(nil), // 3: gid.UploadFileRequest - (*ChatMessage)(nil), // 4: gid.ChatMessage - (*Message)(nil), // 5: gid.Message - (*GenerateRequest)(nil), // 6: gid.GenerateRequest - (*TypesRequest)(nil), // 7: gid.TypesRequest - (*TypesResponse)(nil), // 8: gid.TypesResponse - (*httpbody.HttpBody)(nil), // 9: google.api.HttpBody + (*Empty)(nil), // 3: gid.Empty + (*UploadFileRequest)(nil), // 4: gid.UploadFileRequest + (*ChatMessage)(nil), // 5: gid.ChatMessage + (*Message)(nil), // 6: gid.Message + (*GenerateRequest)(nil), // 7: gid.GenerateRequest + (*TypesRequest)(nil), // 8: gid.TypesRequest + (*TypesResponse)(nil), // 9: gid.TypesResponse + (*httpbody.HttpBody)(nil), // 10: google.api.HttpBody } var file_gid_id_proto_depIdxs = []int32{ - 9, // 0: gid.UploadFileRequest.file:type_name -> google.api.HttpBody - 5, // 1: gid.ChatMessage.msg:type_name -> gid.Message + 10, // 0: gid.UploadFileRequest.file:type_name -> google.api.HttpBody + 6, // 1: gid.ChatMessage.msg:type_name -> gid.Message 1, // 2: gid.GenerateRequest.type:type_name -> gid.GenType - 6, // 3: gid.Id.Generate:input_type -> gid.GenerateRequest - 7, // 4: gid.Id.TypeStream:input_type -> gid.TypesRequest - 7, // 5: gid.Id.Types:input_type -> gid.TypesRequest - 7, // 6: gid.Id.PutTypes:input_type -> gid.TypesRequest - 4, // 7: gid.Id.Chat:input_type -> gid.ChatMessage - 4, // 8: gid.Id.Chat1:input_type -> gid.ChatMessage - 3, // 9: gid.Id.UploadDownload:input_type -> gid.UploadFileRequest - 2, // 10: gid.Id.Generate:output_type -> gid.GenerateResponse - 8, // 11: gid.Id.TypeStream:output_type -> gid.TypesResponse - 8, // 12: gid.Id.Types:output_type -> gid.TypesResponse - 8, // 13: gid.Id.PutTypes:output_type -> gid.TypesResponse - 4, // 14: gid.Id.Chat:output_type -> gid.ChatMessage - 4, // 15: gid.Id.Chat1:output_type -> gid.ChatMessage - 9, // 16: gid.Id.UploadDownload:output_type -> google.api.HttpBody - 10, // [10:17] is the sub-list for method output_type - 3, // [3:10] is the sub-list for method input_type + 7, // 3: gid.Id.Generate:input_type -> gid.GenerateRequest + 8, // 4: gid.Id.TypeStream:input_type -> gid.TypesRequest + 8, // 5: gid.Id.Types:input_type -> gid.TypesRequest + 8, // 6: gid.Id.PutTypes:input_type -> gid.TypesRequest + 5, // 7: gid.Id.Chat:input_type -> gid.ChatMessage + 5, // 8: gid.Id.Chat1:input_type -> gid.ChatMessage + 4, // 9: gid.Id.UploadDownload:input_type -> gid.UploadFileRequest + 3, // 10: gid.Id.DoProxy:input_type -> gid.Empty + 2, // 11: gid.Id.Generate:output_type -> gid.GenerateResponse + 9, // 12: gid.Id.TypeStream:output_type -> gid.TypesResponse + 9, // 13: gid.Id.Types:output_type -> gid.TypesResponse + 9, // 14: gid.Id.PutTypes:output_type -> gid.TypesResponse + 5, // 15: gid.Id.Chat:output_type -> gid.ChatMessage + 5, // 16: gid.Id.Chat1:output_type -> gid.ChatMessage + 10, // 17: gid.Id.UploadDownload:output_type -> google.api.HttpBody + 3, // 18: gid.Id.DoProxy:output_type -> gid.Empty + 11, // [11:19] is the sub-list for method output_type + 3, // [3:11] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension extendee 0, // [0:3] is the sub-list for field type_name @@ -686,7 +731,7 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[1].Exporter = func(v any, i int) any { - switch v := v.(*UploadFileRequest); i { + switch v := v.(*Empty); i { case 0: return &v.state case 1: @@ -698,7 +743,7 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[2].Exporter = func(v any, i int) any { - switch v := v.(*ChatMessage); i { + switch v := v.(*UploadFileRequest); i { case 0: return &v.state case 1: @@ -710,7 +755,7 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[3].Exporter = func(v any, i int) any { - switch v := v.(*Message); i { + switch v := v.(*ChatMessage); i { case 0: return &v.state case 1: @@ -722,7 +767,7 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[4].Exporter = func(v any, i int) any { - switch v := v.(*GenerateRequest); i { + switch v := v.(*Message); i { case 0: return &v.state case 1: @@ -734,7 +779,7 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[5].Exporter = func(v any, i int) any { - switch v := v.(*TypesRequest); i { + switch v := v.(*GenerateRequest); i { case 0: return &v.state case 1: @@ -746,6 +791,18 @@ func file_gid_id_proto_init() { } } file_gid_id_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*TypesRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_gid_id_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*TypesResponse); i { case 0: return &v.state @@ -764,7 +821,7 @@ func file_gid_id_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_gid_id_proto_rawDesc, NumEnums: 2, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go index 345ca93c..ebcc361a 100644 --- a/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go +++ b/internal/example/grpc/pkg/proto/gidpb/id_grpc.pb.go @@ -27,6 +27,7 @@ const ( Id_Chat_FullMethodName = "/gid.Id/Chat" Id_Chat1_FullMethodName = "/gid.Id/Chat1" Id_UploadDownload_FullMethodName = "/gid.Id/UploadDownload" + Id_DoProxy_FullMethodName = "/gid.Id/DoProxy" ) // IdClient is the client API for Id service. @@ -45,6 +46,7 @@ type IdClient interface { // ws: chat1 Chat1(ctx context.Context, opts ...grpc.CallOption) (Id_Chat1Client, error) UploadDownload(ctx context.Context, in *UploadFileRequest, opts ...grpc.CallOption) (*httpbody.HttpBody, error) + DoProxy(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) } type idClient struct { @@ -185,6 +187,15 @@ func (c *idClient) UploadDownload(ctx context.Context, in *UploadFileRequest, op return out, nil } +func (c *idClient) DoProxy(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, Id_DoProxy_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // IdServer is the server API for Id service. // All implementations should embed UnimplementedIdServer // for forward compatibility @@ -201,6 +212,7 @@ type IdServer interface { // ws: chat1 Chat1(Id_Chat1Server) error UploadDownload(context.Context, *UploadFileRequest) (*httpbody.HttpBody, error) + DoProxy(context.Context, *Empty) (*Empty, error) } // UnimplementedIdServer should be embedded to have forward compatible implementations. @@ -228,6 +240,9 @@ func (UnimplementedIdServer) Chat1(Id_Chat1Server) error { func (UnimplementedIdServer) UploadDownload(context.Context, *UploadFileRequest) (*httpbody.HttpBody, error) { return nil, status.Errorf(codes.Unimplemented, "method UploadDownload not implemented") } +func (UnimplementedIdServer) DoProxy(context.Context, *Empty) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method DoProxy not implemented") +} // UnsafeIdServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to IdServer will @@ -385,6 +400,24 @@ func _Id_UploadDownload_Handler(srv interface{}, ctx context.Context, dec func(i return interceptor(ctx, in, info, handler) } +func _Id_DoProxy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdServer).DoProxy(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Id_DoProxy_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdServer).DoProxy(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + // Id_ServiceDesc is the grpc.ServiceDesc for Id service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -408,6 +441,10 @@ var Id_ServiceDesc = grpc.ServiceDesc{ MethodName: "UploadDownload", Handler: _Id_UploadDownload_Handler, }, + { + MethodName: "DoProxy", + Handler: _Id_DoProxy_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/internal/example/grpc/proto/gid/id.proto b/internal/example/grpc/proto/gid/id.proto index 482d67fa..53b3d9fe 100644 --- a/internal/example/grpc/proto/gid/id.proto +++ b/internal/example/grpc/proto/gid/id.proto @@ -26,7 +26,7 @@ service Id { rpc Generate (GenerateRequest) returns (GenerateResponse) { option (lava.rpc.options) = { name: "id.gen", - tags: [{key: "internal",value: "true"},{key: "hello",value: "world"}] + tags: [{key: "internal",value: "true"}, {key: "hello",value: "world"}] }; option (google.api.http) = { post: "/v1/id/generate" @@ -70,6 +70,15 @@ service Id { body: "file" }; } + + rpc DoProxy (Empty) returns (Empty) { + option (google.api.http) = { + get: "/proxy/test" + }; + } +} + +message Empty { } message UploadFileRequest { diff --git a/internal/middlewares/middleware_accesslog/middleware.go b/internal/middlewares/middleware_accesslog/middleware.go index 8508cda7..f4dc9fe4 100644 --- a/internal/middlewares/middleware_accesslog/middleware.go +++ b/internal/middlewares/middleware_accesslog/middleware.go @@ -7,7 +7,6 @@ import ( "github.com/gofiber/utils" "github.com/pubgo/funk/convert" - "github.com/pubgo/funk/errors" "github.com/pubgo/funk/errors/errutil" "github.com/pubgo/funk/generic" "github.com/pubgo/funk/log" @@ -98,7 +97,7 @@ func (l LogMiddleware) Middleware(next lava.HandlerFunc) lava.HandlerFunc { e = l.logger.Info().Func(log.WithEvent(evt)) //} } else { - errors.Debug(gErr) + //errors.Debug(gErr) e = l.logger.Err(gErr).Func(log.WithEvent(evt)) pb := errutil.ParseError(gErr) diff --git a/internal/middlewares/middleware_service_info/middleware.go b/internal/middlewares/middleware_service_info/middleware.go index 3b268c12..cec8cb3b 100644 --- a/internal/middlewares/middleware_service_info/middleware.go +++ b/internal/middlewares/middleware_service_info/middleware.go @@ -27,7 +27,7 @@ func New() lava.Middleware { ctx = lava.CreateCtxWithReqID(ctx, reqId) defer func() { - if gErr != nil && rsp != nil { + if rsp != nil { rsp.Header().Set(httputil.HeaderXRequestID, reqId) } }() diff --git a/pkg/grpcutil/util.go b/pkg/grpcutil/util.go index ef1c49cb..6f81ad5a 100644 --- a/pkg/grpcutil/util.go +++ b/pkg/grpcutil/util.go @@ -18,11 +18,11 @@ import ( ) const ( - ClientNameKey = "client-name" - ClientIpKey = "client-ip" - ClientHostnameKey = "client-hostname" - ClientPathKey = "client-path" - ClientVersionKey = "client-version" + ClientNameKey = "x-lava-client-name" + ClientIpKey = "x-lava-client-ip" + ClientHostnameKey = "x-lava-client-hostname" + ClientPathKey = "x-lava-client-path" + ClientVersionKey = "x-lava-client-version" ) // WithClientApp 获取对端应用名称 diff --git a/servers/grpcs/inner_server.go b/servers/grpcs/inner_server.go index b127b270..ec6baa79 100644 --- a/servers/grpcs/inner_server.go +++ b/servers/grpcs/inner_server.go @@ -63,7 +63,7 @@ func NewInner(handlers []lava.GrpcRouter, grpcProxy []lava.GrpcProxy, dixMiddlew Log: log, Metric: metric, }, - srvMidMap[desc.ServiceName]..., + h.Middlewares()..., ) for i := range desc.Methods { @@ -97,7 +97,7 @@ func grpcMethodHandlerWrapper(cli grpc.ClientConnInterface, fullPath string, inT var trailer metadata.MD err := cli.Invoke(ctx, fullPath, req, out, append([]grpc.CallOption{}, grpc.Header(&header), grpc.Trailer(&trailer))...) if err != nil { - return nil, err + return nil, errors.WrapCaller(err) } return out, nil } diff --git a/servers/grpcs/server.go b/servers/grpcs/server.go index b0b135cb..b5bc794b 100644 --- a/servers/grpcs/server.go +++ b/servers/grpcs/server.go @@ -168,7 +168,7 @@ func (s *serviceImpl) DixInject( app := fiber.New() app.Group("/debug", httputil.StripPrefix(filepath.Join(conf.BaseUrl, "/debug"), debug.Handler)) - app.Use(handlerHttpMiddle(globalMiddlewares)) + //app.Use(handlerHttpMiddle(globalMiddlewares)) for _, h := range httpRouters { //srv := doc.WithService() //for _, an := range h.Annotation() { @@ -184,7 +184,7 @@ func (s *serviceImpl) DixInject( panic("http handler prefix is required") } - g := app.Group(h.Prefix(), handlerHttpMiddle(h.Middlewares())) + g := app.Group(h.Prefix(), handlerHttpMiddle(append(globalMiddlewares, h.Middlewares()...))) h.Router(g) if m, ok := h.(lava.Close); ok { @@ -197,16 +197,6 @@ func (s *serviceImpl) DixInject( } for _, handler := range grpcRouters { - //srv := doc.WithService() - //for _, an := range h.Annotation() { - // switch a := an.(type) { - // case *annotation.Openapi: - // if a.ServiceName != "" { - // srv.SetName(a.ServiceName) - // } - // } - //} - h, ok := handler.(lava.HttpRouter) if !ok { continue @@ -216,7 +206,7 @@ func (s *serviceImpl) DixInject( panic("http handler prefix is required") } - g := app.Group(h.Prefix(), handlerHttpMiddle(h.Middlewares())) + g := app.Group(h.Prefix(), handlerHttpMiddle(append(globalMiddlewares, h.Middlewares()...))) h.Router(g) if m, ok := h.(lava.Close); ok { @@ -326,6 +316,7 @@ func (s *serviceImpl) DixInject( if len(gw) > 0 { mux = gw[0] } + srvMidMap := make(map[string][]lava.Middleware) for _, h := range grpcRouters { desc := h.ServiceDesc() @@ -387,12 +378,7 @@ func (s *serviceImpl) DixInject( srvMidMap[desc.ServiceName]..., ) - for i := range desc.Methods { - var fullPath = fmt.Sprintf("/%s/%s", desc.ServiceName, desc.Methods[i].MethodName) - inT, outT := getMthType(desc.ServiceName, desc.Methods[i].MethodName) - desc.Methods[i].Handler = grpcMethodHandlerWrapper(cli, fullPath, inT, outT) - } - mux.RegisterService(desc, h) + mux.RegisterProxy(desc, h, cli) } mux.SetUnaryInterceptor(handlerUnaryMiddle(srvMidMap)) From a04ba2f58e704af45f96b18d347841b7141bd4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 23:48:08 +0800 Subject: [PATCH 34/41] fix: barry 2024-07-26 23:48:08 --- clients/grpcc/middleware.go | 12 ++++++------ cmds/migratecmd/cmd.go | 2 +- core/discovery/_docs.go | 1 + {lava => core/lavacontexts}/context.go | 15 ++++++++------- core/{ => orm}/migrates/aaa.go | 0 core/{ => orm}/migrates/config.go | 0 core/{ => orm}/migrates/migrate.go | 0 .../gid_handler/handler_proxy_server.go | 3 ++- .../middleware_accesslog/middleware.go | 5 +++-- .../middlewares/middleware_metric/middleware.go | 3 ++- .../middleware_service_info/middleware.go | 9 +++++---- pkg/gateway/util.go | 2 +- servers/grpcs/middleware.go | 17 +++++++++-------- 13 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 core/discovery/_docs.go rename {lava => core/lavacontexts}/context.go (75%) rename core/{ => orm}/migrates/aaa.go (100%) rename core/{ => orm}/migrates/config.go (100%) rename core/{ => orm}/migrates/migrate.go (100%) diff --git a/clients/grpcc/middleware.go b/clients/grpcc/middleware.go index 8ba65d00..0c3baf60 100644 --- a/clients/grpcc/middleware.go +++ b/clients/grpcc/middleware.go @@ -2,12 +2,12 @@ package grpcc import ( "context" + "github.com/pubgo/lava/core/lavacontexts" "strings" "time" - "github.com/pubgo/funk/errors" - "github.com/pubgo/funk/convert" + "github.com/pubgo/funk/errors" "github.com/pubgo/funk/strutil" "github.com/pubgo/lava/clients/grpcc/grpcc_config" "github.com/pubgo/lava/lava" @@ -106,12 +106,12 @@ func unaryInterceptor(middlewares []lava.Middleware) grpc.UnaryClientInterceptor } reqId := strutil.FirstFnNotEmpty( - func() string { return lava.GetReqID(ctx) }, + func() string { return lavacontexts.GetReqID(ctx) }, func() string { return string(rpcReq.Header().Peek(httputil.HeaderXRequestID)) }, func() string { return xid.New().String() }, ) rpcReq.Header().Set(httputil.HeaderXRequestID, reqId) - ctx = lava.CreateCtxWithReqID(ctx, reqId) + ctx = lavacontexts.CreateCtxWithReqID(ctx, reqId) _, err = unaryWrapper(ctx, rpcReq) return errors.WrapCaller(err) @@ -173,12 +173,12 @@ func streamInterceptor(middlewares []lava.Middleware) grpc.StreamClientIntercept md2Head(md, header) reqId := strutil.FirstFnNotEmpty( - func() string { return lava.GetReqID(ctx) }, + func() string { return lavacontexts.GetReqID(ctx) }, func() string { return string(header.Peek(httputil.HeaderXRequestID)) }, func() string { return xid.New().String() }, ) header.Set(httputil.HeaderXRequestID, reqId) - ctx = lava.CreateCtxWithReqID(ctx, reqId) + ctx = lavacontexts.CreateCtxWithReqID(ctx, reqId) rsp, err := wrapperStream(ctx, &request{ diff --git a/cmds/migratecmd/cmd.go b/cmds/migratecmd/cmd.go index 6862ca36..ed75453c 100644 --- a/cmds/migratecmd/cmd.go +++ b/cmds/migratecmd/cmd.go @@ -14,8 +14,8 @@ import ( "github.com/urfave/cli/v3" "gorm.io/gen" - "github.com/pubgo/lava/core/migrates" "github.com/pubgo/lava/core/orm" + "github.com/pubgo/lava/core/orm/migrates" ) type params struct { diff --git a/core/discovery/_docs.go b/core/discovery/_docs.go new file mode 100644 index 00000000..5844159a --- /dev/null +++ b/core/discovery/_docs.go @@ -0,0 +1 @@ +package discovery diff --git a/lava/context.go b/core/lavacontexts/context.go similarity index 75% rename from lava/context.go rename to core/lavacontexts/context.go index f7b853f3..2a5b443d 100644 --- a/lava/context.go +++ b/core/lavacontexts/context.go @@ -1,8 +1,9 @@ -package lava +package lavacontexts import ( "context" + "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/proto/lavapbv1" "github.com/rs/xid" ) @@ -57,18 +58,18 @@ var ( rspHeader = ctxKey(xid.New().String()) ) -func CreateReqHeader(ctx context.Context, header *RequestHeader) context.Context { +func CreateReqHeader(ctx context.Context, header *lava.RequestHeader) context.Context { return context.WithValue(ctx, reqHeader, header) } -func ReqHeader(ctx context.Context) *RequestHeader { - return ctx.Value(reqHeader).(*RequestHeader) +func ReqHeader(ctx context.Context) *lava.RequestHeader { + return ctx.Value(reqHeader).(*lava.RequestHeader) } -func CreateRspHeader(ctx context.Context, header *ResponseHeader) context.Context { +func CreateRspHeader(ctx context.Context, header *lava.ResponseHeader) context.Context { return context.WithValue(ctx, rspHeader, header) } -func RspHeader(ctx context.Context) *ResponseHeader { - return ctx.Value(rspHeader).(*ResponseHeader) +func RspHeader(ctx context.Context) *lava.ResponseHeader { + return ctx.Value(rspHeader).(*lava.ResponseHeader) } diff --git a/core/migrates/aaa.go b/core/orm/migrates/aaa.go similarity index 100% rename from core/migrates/aaa.go rename to core/orm/migrates/aaa.go diff --git a/core/migrates/config.go b/core/orm/migrates/config.go similarity index 100% rename from core/migrates/config.go rename to core/orm/migrates/config.go diff --git a/core/migrates/migrate.go b/core/orm/migrates/migrate.go similarity index 100% rename from core/migrates/migrate.go rename to core/orm/migrates/migrate.go diff --git a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go index 111b8195..4aac47ea 100644 --- a/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go +++ b/internal/example/grpc/internal/handlers/gid_handler/handler_proxy_server.go @@ -3,6 +3,7 @@ package gid_handler import ( "context" "fmt" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/lava/internal/example/grpc/pkg/proto/gidpb" "github.com/pubgo/lava/lava" @@ -23,7 +24,7 @@ type IdProxyServer struct { func (i IdProxyServer) Echo(ctx context.Context, req *gidpb.EchoReq) (*gidpb.EchoRsp, error) { fmt.Println("get echo request", req.String()) - fmt.Println("req", lava.ReqHeader(ctx).String()) + fmt.Println("req", lavacontexts.ReqHeader(ctx).String()) return &gidpb.EchoRsp{Hello: req.Hello}, nil } diff --git a/internal/middlewares/middleware_accesslog/middleware.go b/internal/middlewares/middleware_accesslog/middleware.go index f4dc9fe4..d8046d26 100644 --- a/internal/middlewares/middleware_accesslog/middleware.go +++ b/internal/middlewares/middleware_accesslog/middleware.go @@ -3,6 +3,7 @@ package middleware_accesslog import ( "context" "fmt" + "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/gofiber/utils" @@ -46,7 +47,7 @@ func (l LogMiddleware) Middleware(next lava.HandlerFunc) lava.HandlerFunc { evt.Str("referer", referer) } - reqId := lava.GetReqID(ctx) + reqId := lavacontexts.GetReqID(ctx) evt.Str("req_id", reqId) evt.Int64("start_at", now.Unix()) evt.Str("service", req.Service()) @@ -55,7 +56,7 @@ func (l LogMiddleware) Middleware(next lava.HandlerFunc) lava.HandlerFunc { evt.Bool("client", req.Client()) evt.Str("version", version.Version()) - clientInfo := lava.GetClientInfo(ctx) + clientInfo := lavacontexts.GetClientInfo(ctx) if clientInfo != nil { evt.Str(grpcutil.ClientNameKey, clientInfo.GetName()) evt.Str(grpcutil.ClientPathKey, clientInfo.GetPath()) diff --git a/internal/middlewares/middleware_metric/middleware.go b/internal/middlewares/middleware_metric/middleware.go index e2ef9267..2a8ee60f 100644 --- a/internal/middlewares/middleware_metric/middleware.go +++ b/internal/middlewares/middleware_metric/middleware.go @@ -2,6 +2,7 @@ package middleware_metric import ( "context" + "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/pubgo/funk/generic" @@ -53,7 +54,7 @@ func (m MetricMiddleware) Middleware(next lava.HandlerFunc) lava.HandlerFunc { grpcServerRpcCallTotal(m.m, req.Operation()) - clientInfo := lava.GetClientInfo(ctx) + clientInfo := lavacontexts.GetClientInfo(ctx) if !req.Client() && clientInfo != nil { m.m.Tagged(metrics.Tags{ "server_name": running.Project, diff --git a/internal/middlewares/middleware_service_info/middleware.go b/internal/middlewares/middleware_service_info/middleware.go index cec8cb3b..27bc7f1d 100644 --- a/internal/middlewares/middleware_service_info/middleware.go +++ b/internal/middlewares/middleware_service_info/middleware.go @@ -2,6 +2,7 @@ package middleware_service_info import ( "context" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/funk/convert" "github.com/pubgo/funk/running" @@ -20,11 +21,11 @@ func New() lava.Middleware { Next: func(next lava.HandlerFunc) lava.HandlerFunc { return func(ctx context.Context, req lava.Request) (rsp lava.Response, gErr error) { reqId := strutil.FirstFnNotEmpty( - func() string { return lava.GetReqID(ctx) }, + func() string { return lavacontexts.GetReqID(ctx) }, func() string { return string(req.Header().Peek(httputil.HeaderXRequestID)) }, func() string { return xid.New().String() }, ) - ctx = lava.CreateCtxWithReqID(ctx, reqId) + ctx = lavacontexts.CreateCtxWithReqID(ctx, reqId) defer func() { if rsp != nil { @@ -70,8 +71,8 @@ func New() lava.Middleware { } } - ctx = lava.CreateCtxWithClientInfo(ctx, clientInfo) - ctx = lava.CreateCtxWithServerInfo(ctx, serverInfo) + ctx = lavacontexts.CreateCtxWithClientInfo(ctx, clientInfo) + ctx = lavacontexts.CreateCtxWithServerInfo(ctx, serverInfo) return next(ctx, req) } diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index f005651f..91c3af28 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -223,7 +223,7 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s } if err := handlerHttpRoute(rule, cb); err != nil { - return errors.Format("failed to add REST route (add'l binding #%d): %w", i+1, err) + return errors.Format("failed to add REST route (add binding #%d): %w", i+1, err) } } diff --git a/servers/grpcs/middleware.go b/servers/grpcs/middleware.go index ba6c7fd2..48aa5bd7 100644 --- a/servers/grpcs/middleware.go +++ b/servers/grpcs/middleware.go @@ -3,6 +3,7 @@ package grpcs import ( "context" "fmt" + "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/gofiber/fiber/v2" @@ -104,11 +105,11 @@ func handlerUnaryMiddle(middlewares map[string][]lava.Middleware) grpc.UnaryServ } reqId := strutil.FirstFnNotEmpty( - func() string { return lava.GetReqID(ctx) }, + func() string { return lavacontexts.GetReqID(ctx) }, func() string { return string(rpcReq.Header().Peek(httputil.HeaderXRequestID)) }, func() string { return xid.New().String() }, ) - ctx = lava.CreateCtxWithReqID(ctx, reqId) + ctx = lavacontexts.CreateCtxWithReqID(ctx, reqId) reqHeader.Set(httputil.HeaderXRequestID, reqId) reqHeader.Set(httputil.HeaderXRequestVersion, version.Version()) @@ -132,8 +133,8 @@ func handlerUnaryMiddle(middlewares map[string][]lava.Middleware) grpc.UnaryServ }() - ctx = lava.CreateReqHeader(ctx, reqHeader) - ctx = lava.CreateRspHeader(ctx, rpcReq.rspHeader) + ctx = lavacontexts.CreateReqHeader(ctx, reqHeader) + ctx = lavacontexts.CreateRspHeader(ctx, rpcReq.rspHeader) rsp, err := lava.Chain(middlewares[srvName]...).Middleware(unaryWrapper)(ctx, rpcReq) if err != nil { pb := errutil.ParseError(err) @@ -239,15 +240,15 @@ func handlerStreamMiddle(middlewares map[string][]lava.Middleware) grpc.StreamSe } reqId := strutil.FirstFnNotEmpty( - func() string { return lava.GetReqID(ctx) }, + func() string { return lavacontexts.GetReqID(ctx) }, func() string { return string(rpcReq.Header().Peek(httputil.HeaderXRequestID)) }, func() string { return xid.New().String() }, ) rpcReq.Header().Set(httputil.HeaderXRequestID, reqId) - ctx = lava.CreateCtxWithReqID(ctx, reqId) + ctx = lavacontexts.CreateCtxWithReqID(ctx, reqId) - ctx = lava.CreateReqHeader(ctx, header) - ctx = lava.CreateRspHeader(ctx, rpcReq.rspHeader) + ctx = lavacontexts.CreateReqHeader(ctx, header) + ctx = lavacontexts.CreateRspHeader(ctx, rpcReq.rspHeader) rsp, err := lava.Chain(middlewares[srvName]...).Middleware(streamWrapper)(ctx, rpcReq) if err != nil { pb := errutil.ParseError(err) From 1e13fd4ae58c25af0b90f0f9e08998cfb4d96657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 23:48:55 +0800 Subject: [PATCH 35/41] fix: barry 2024-07-26 23:48:55 --- .golangci.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 1cb1019f..9639afbd 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -2,20 +2,20 @@ linters: fast: true disable-all: true enable: - - bodyclose # checks whether HTTP response body is closed successfully +# - bodyclose # checks whether HTTP response body is closed successfully - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases - gosimple # Linter for Go source code that specializes in simplifying a code - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # Detects when assignments to existing variables are not used - - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) - - goconst # Finds repeated strings that could be replaced by a constant +# - ineffassign # Detects when assignments to existing variables are not used +# - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) +# - goconst # Finds repeated strings that could be replaced by a constant - goimports # Goimports does everything that gofmt does. Additionally it checks unused imports - - goprintffuncname # Checks that printf-like functions are named with f at the end - - nolintlint # Reports ill-formed or insufficient nolint directives - - rowserrcheck # checks whether Err of rows is checked successfully +# - goprintffuncname # Checks that printf-like functions are named with f at the end +# - nolintlint # Reports ill-formed or insufficient nolint directives +# - rowserrcheck # checks whether Err of rows is checked successfully - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks - - unconvert # Remove unnecessary type conversions - - unparam # Reports unused function parameters +# - unconvert # Remove unnecessary type conversions +# - unparam # Reports unused function parameters # - unused # Checks Go code for unused constants, variables, functions and types issues: From 7798b1e213dbedfd40e5c7bf60d1dfdedc37a5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Fri, 26 Jul 2024 23:56:26 +0800 Subject: [PATCH 36/41] fix: barry 2024-07-26 23:56:26 --- .github/workflows/lint-test.yml | 68 +++++++++---------- internal/example/grpc/Makefile | 2 +- .../example/grpc/{ => cmds}/main_proxy.go | 0 pkg/gateway/util.go | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) rename internal/example/grpc/{ => cmds}/main_proxy.go (100%) diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index fffb0b20..0d2cbd1e 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -12,44 +12,44 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.22 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.22 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - skip-go-installation: true - args: --timeout 3m --verbose + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + skip-go-installation: true + args: --timeout 3m --verbose test: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.22 - - - name: Collect dependencies - run: | - go mod download - go install gotest.tools/gotestsum@latest - - - name: Run unit tests - run: gotestsum --junitfile unit-tests.xml -- -gcflags=-l ./... - - - name: Test report - uses: dorny/test-reporter@v1 - if: success() || failure() - with: - name: Test report - path: unit-tests.xml - reporter: java-junit - fail-on-error: false + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.22 + + - name: Collect dependencies + run: | + go mod download + go install gotest.tools/gotestsum@latest + + - name: Run unit tests + run: gotestsum --junitfile unit-tests.xml -- -gcflags=-l ./... + + - name: Test report + uses: dorny/test-reporter@v1 + if: success() || failure() + with: + name: Test report + path: unit-tests.xml + reporter: java-junit + fail-on-error: false diff --git a/internal/example/grpc/Makefile b/internal/example/grpc/Makefile index 8773ed0f..09ab0227 100644 --- a/internal/example/grpc/Makefile +++ b/internal/example/grpc/Makefile @@ -13,7 +13,7 @@ LDFLAGS=-ldflags " \ " run_proxy: - enable_debug=true server_grpc_port=50052 server_http_port=8081 go run ${LDFLAGS} -v main_proxy.go grpc + enable_debug=true server_grpc_port=50052 server_http_port=8081 go run ${LDFLAGS} -v cmds/main_proxy.go grpc run: enable_debug=true server_grpc_port=50051 server_http_port=8080 go run ${LDFLAGS} -v main.go grpc diff --git a/internal/example/grpc/main_proxy.go b/internal/example/grpc/cmds/main_proxy.go similarity index 100% rename from internal/example/grpc/main_proxy.go rename to internal/example/grpc/cmds/main_proxy.go diff --git a/pkg/gateway/util.go b/pkg/gateway/util.go index 91c3af28..2eebc9b6 100644 --- a/pkg/gateway/util.go +++ b/pkg/gateway/util.go @@ -223,7 +223,7 @@ func handlerHttpRoute(httpRule *annotations.HttpRule, cb func(mth string, path s } if err := handlerHttpRoute(rule, cb); err != nil { - return errors.Format("failed to add REST route (add binding #%d): %w", i+1, err) + return errors.Format("failed to add REST route (add binding #%d): %v", i+1, err) } } From 1bb72218c2fa1c47c5acc8831f21fe5f8effdf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 27 Jul 2024 00:02:11 +0800 Subject: [PATCH 37/41] fix: barry 2024-07-27 00:02:11 --- .golangci.yaml | 1 + clients/grpcc/middleware.go | 2 +- internal/example/grpc/Makefile | 1 + .../middleware_accesslog/middleware.go | 2 +- .../middleware_metric/middleware.go | 2 +- .../middleware_service_info/middleware.go | 2 +- pkg/gateway/internal/routertree/parser.go | 1 + pkg/gateway/stream_inprocess.go | 84 +++++++++---------- pkg/gateway/stream_proxy.go | 3 +- servers/grpcs/middleware.go | 2 +- 10 files changed, 48 insertions(+), 52 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 9639afbd..133d7867 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,6 +23,7 @@ issues: - internal/example - cmds - vendor + - pkg/proto exclude-generated: strict exclude-dirs-use-default: true exclude-case-sensitive: false diff --git a/clients/grpcc/middleware.go b/clients/grpcc/middleware.go index 0c3baf60..3940142a 100644 --- a/clients/grpcc/middleware.go +++ b/clients/grpcc/middleware.go @@ -2,7 +2,6 @@ package grpcc import ( "context" - "github.com/pubgo/lava/core/lavacontexts" "strings" "time" @@ -10,6 +9,7 @@ import ( "github.com/pubgo/funk/errors" "github.com/pubgo/funk/strutil" "github.com/pubgo/lava/clients/grpcc/grpcc_config" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/grpcutil" "github.com/pubgo/lava/pkg/httputil" diff --git a/internal/example/grpc/Makefile b/internal/example/grpc/Makefile index 09ab0227..311043e0 100644 --- a/internal/example/grpc/Makefile +++ b/internal/example/grpc/Makefile @@ -29,3 +29,4 @@ vet: protobuf: protobuild vendor protobuild gen + diff --git a/internal/middlewares/middleware_accesslog/middleware.go b/internal/middlewares/middleware_accesslog/middleware.go index d8046d26..b5f3ad33 100644 --- a/internal/middlewares/middleware_accesslog/middleware.go +++ b/internal/middlewares/middleware_accesslog/middleware.go @@ -3,7 +3,6 @@ package middleware_accesslog import ( "context" "fmt" - "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/gofiber/utils" @@ -13,6 +12,7 @@ import ( "github.com/pubgo/funk/log" "github.com/pubgo/funk/proto/errorpb" "github.com/pubgo/funk/version" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/grpcutil" "github.com/rs/zerolog" diff --git a/internal/middlewares/middleware_metric/middleware.go b/internal/middlewares/middleware_metric/middleware.go index 2a8ee60f..06aab333 100644 --- a/internal/middlewares/middleware_metric/middleware.go +++ b/internal/middlewares/middleware_metric/middleware.go @@ -2,11 +2,11 @@ package middleware_metric import ( "context" - "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/pubgo/funk/generic" "github.com/pubgo/funk/running" + "github.com/pubgo/lava/core/lavacontexts" "github.com/uber-go/tally/v4" "github.com/pubgo/lava/core/metrics" diff --git a/internal/middlewares/middleware_service_info/middleware.go b/internal/middlewares/middleware_service_info/middleware.go index 27bc7f1d..debfa106 100644 --- a/internal/middlewares/middleware_service_info/middleware.go +++ b/internal/middlewares/middleware_service_info/middleware.go @@ -2,12 +2,12 @@ package middleware_service_info import ( "context" - "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/funk/convert" "github.com/pubgo/funk/running" "github.com/pubgo/funk/strutil" "github.com/pubgo/funk/version" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/lava/lava" "github.com/pubgo/lava/pkg/grpcutil" "github.com/pubgo/lava/pkg/httputil" diff --git a/pkg/gateway/internal/routertree/parser.go b/pkg/gateway/internal/routertree/parser.go index 0dd98f56..5bf95dc0 100644 --- a/pkg/gateway/internal/routertree/parser.go +++ b/pkg/gateway/internal/routertree/parser.go @@ -1,3 +1,4 @@ +//nolint:all package routertree import ( diff --git a/pkg/gateway/stream_inprocess.go b/pkg/gateway/stream_inprocess.go index 07bc3010..00c18642 100644 --- a/pkg/gateway/stream_inprocess.go +++ b/pkg/gateway/stream_inprocess.go @@ -1,48 +1,40 @@ package gateway -import ( - "context" - - "github.com/fullstorydev/grpchan/inprocgrpc" - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -var _ grpc.ServerStream = (*serverInProcess)(nil) - -type serverInProcess struct { - ctx context.Context - method string - args any - reply any - opts []grpc.CallOption - desc *grpc.StreamDesc -} - -func (s serverInProcess) SetHeader(md metadata.MD) error { - //TODO implement me - panic("implement me") -} - -func (s serverInProcess) SendHeader(md metadata.MD) error { - //TODO implement me - panic("implement me") -} - -func (s serverInProcess) SetTrailer(md metadata.MD) { - //TODO implement me - panic("implement me") -} - -func (s serverInProcess) Context() context.Context { - return s.ctx -} - -func (s serverInProcess) SendMsg(m any) error { - s.reply = m - return nil -} - -func (s serverInProcess) RecvMsg(m any) error { - return inprocgrpc.ProtoCloner{}.Copy(m, s.args) -} +//var _ grpc.ServerStream = (*serverInProcess)(nil) +// +//type serverInProcess struct { +// ctx context.Context +// method string +// args any +// reply any +// opts []grpc.CallOption +// desc *grpc.StreamDesc +//} +// +//func (s serverInProcess) SetHeader(md metadata.MD) error { +// //TODO implement me +// panic("implement me") +//} +// +//func (s serverInProcess) SendHeader(md metadata.MD) error { +// //TODO implement me +// panic("implement me") +//} +// +//func (s serverInProcess) SetTrailer(md metadata.MD) { +// //TODO implement me +// panic("implement me") +//} +// +//func (s serverInProcess) Context() context.Context { +// return s.ctx +//} +// +//func (s serverInProcess) SendMsg(m any) error { +// s.reply = m +// return nil +//} +// +//func (s serverInProcess) RecvMsg(m any) error { +// return inprocgrpc.ProtoCloner{}.Copy(m, s.args) +//} diff --git a/pkg/gateway/stream_proxy.go b/pkg/gateway/stream_proxy.go index 74404ce2..a7b2e45f 100644 --- a/pkg/gateway/stream_proxy.go +++ b/pkg/gateway/stream_proxy.go @@ -8,6 +8,7 @@ import ( "io" "github.com/pubgo/funk/errors" + "github.com/pubgo/lava/internal/logutil" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -61,7 +62,7 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error if s2cErr == io.EOF { // this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./ // the clientStream>serverStream may continue pumping though. - clientStream.CloseSend() + logutil.HandlerErr(clientStream.CloseSend()) } else { // however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need // to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and diff --git a/servers/grpcs/middleware.go b/servers/grpcs/middleware.go index 48aa5bd7..dcf649dc 100644 --- a/servers/grpcs/middleware.go +++ b/servers/grpcs/middleware.go @@ -3,7 +3,6 @@ package grpcs import ( "context" "fmt" - "github.com/pubgo/lava/core/lavacontexts" "time" "github.com/gofiber/fiber/v2" @@ -14,6 +13,7 @@ import ( "github.com/pubgo/funk/proto/errorpb" "github.com/pubgo/funk/strutil" "github.com/pubgo/funk/version" + "github.com/pubgo/lava/core/lavacontexts" "github.com/pubgo/lava/pkg/proto/lavapbv1" "github.com/rs/xid" "github.com/valyala/fasthttp" From a64856886f2b6cf9c26806617971dab6d79c0eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 27 Jul 2024 00:08:02 +0800 Subject: [PATCH 38/41] fix: barry 2024-07-27 00:08:02 --- Makefile | 49 ++++++------------------------------------------- cover.html | 0 2 files changed, 6 insertions(+), 43 deletions(-) create mode 100644 cover.html diff --git a/Makefile b/Makefile index 6c6e74f7..42e7fbb8 100644 --- a/Makefile +++ b/Makefile @@ -13,55 +13,20 @@ LDFLAGS=-ldflags " \ -X '${Base}/version.project=${Project}' \ " -.PHONY: build -build: - go build ${LDFLAGS} -mod vendor -v -o bin/main cmd/lava/main.go - -.PHONY: install -install: - @go build ${LDFLAGS} -mod vendor -tags trace -o lava -v cmd/lava/*.go - @mv lava ${GOPATH}/bin/lava - -build_hello_test: - @go build ${LDFLAGS} -mod vendor -v -o main example/hello/main.go - -.PHONY: test./ma +.PHONY: test test: @go test -short -race -v ./... -cover -ci: - @golangci-lint run -v --timeout=5m - -.PHONY: gen -proto-plugin-gen: - cd cmd/protoc-gen-errors && go install -v . - -.PHONY: example -example: - go build ${LDFLAGS} -mod vendor -v -o main example/*.go - -docker: - docker build -t lug . - -build-all: - go build -tags "kcp quic" ./... - +.PHONY: cover cover: gocov test -tags "kcp quic" ./... | gocov-html > cover.html open cover.html -check-libs: - GIT_TERMINAL_PROMPT=1 GO111MODULE=on go list -m -u all | column -t - -update-libs: - GIT_TERMINAL_PROMPT=1 GO111MODULE=on go get -u -v ./... - -mod-tidy: - GIT_TERMINAL_PROMPT=1 GO111MODULE=on go mod tidy - +.PHONY: vet vet: @go vet ./... +.PHONY: generate generate: @go generate ./... @@ -71,14 +36,12 @@ deps: @go install -v github.com/tinylib/msgp @go install -v github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 -lint: - @golangci-lint run --skip-dirs-use-default --timeout 3m0s - .PHONY: protobuf protobuf: protobuild vendor protobuild gen +.PHONY: lint lint: golangci-lint --version - golangci-lint run --timeout 3m --verbose + golangci-lint run --timeout 3m --verbose ./... diff --git a/cover.html b/cover.html new file mode 100644 index 00000000..e69de29b From 23a83ee705def6edee6c5813f5913531cfbddf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 27 Jul 2024 00:08:14 +0800 Subject: [PATCH 39/41] fix: barry 2024-07-27 00:08:14 --- cover.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cover.html diff --git a/cover.html b/cover.html deleted file mode 100644 index e69de29b..00000000 From 8ab209e9fa662436d369d5e4d175f6790de17eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Sat, 27 Jul 2024 13:36:41 +0800 Subject: [PATCH 40/41] fix: barry 2024-07-27 13:36:41 --- protobuf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf.yaml b/protobuf.yaml index 3b49a2ce..f71fad68 100644 --- a/protobuf.yaml +++ b/protobuf.yaml @@ -1,4 +1,4 @@ -checksum: 7420716c6267aaeccc1cedb3ff5beb63d54ad75a +checksum: 7fbdb7a7a048f416861d2e7a3221d7ae80df14bf vendor: .proto base: out: ./pkg From 77f2fd632663fc590ed4d85a17f0ef3c5b1618ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BE=E9=87=8C=28barry=29?= Date: Mon, 29 Jul 2024 21:19:41 +0800 Subject: [PATCH 41/41] fix: barry 2024-07-29 21:19:41 --- core/logging/factory.go | 2 +- core/logging/logext/stdlog/_doc.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 core/logging/logext/stdlog/_doc.go diff --git a/core/logging/factory.go b/core/logging/factory.go index e7d9299a..b234d0bd 100644 --- a/core/logging/factory.go +++ b/core/logging/factory.go @@ -13,7 +13,7 @@ var factories = make(map[string]Factory) func List() map[string]Factory { return factories } func Register(name string, factory Factory) { defer recovery.Exit() - assert.If(name == "" || factory == nil, "[factory,name] should not be null") + assert.If(name == "" || factory == nil, "[factory, name] should not be null") assert.If(factories[name] != nil, "[factory] %s already exists", name) factories[name] = factory } diff --git a/core/logging/logext/stdlog/_doc.go b/core/logging/logext/stdlog/_doc.go new file mode 100644 index 00000000..5acec5be --- /dev/null +++ b/core/logging/logext/stdlog/_doc.go @@ -0,0 +1,3 @@ +package stdlog + +// https://github.com/samber/slog-zerolog