diff --git a/grpcmux/component.go b/grpcmux/component.go index 26e151d..4ba3078 100644 --- a/grpcmux/component.go +++ b/grpcmux/component.go @@ -10,6 +10,10 @@ func initComponents(conf *config.Config) { } func initLogging(conf *config.Config) { + if conf == nil { + return + } + level := conf.GetString("level", "debug") encoding := conf.GetString("encoding", "console") outputPath := conf.GetString("output", "") diff --git a/sample/grpc-server/go.mod b/sample/grpc-server/go.mod index 9c6e4b3..ecc2791 100644 --- a/sample/grpc-server/go.mod +++ b/sample/grpc-server/go.mod @@ -3,6 +3,6 @@ module github.com/skema-dev/skema-go/sample/grpc-server go 1.16 require ( - github.com/skema-dev/skema-go v0.0.0-20220427180038-06103d6faceb + github.com/skema-dev/skema-go v1.0.0 google.golang.org/grpc v1.45.0 ) diff --git a/sample/grpc-server/go.sum b/sample/grpc-server/go.sum index 162d8f0..ab30592 100644 --- a/sample/grpc-server/go.sum +++ b/sample/grpc-server/go.sum @@ -447,8 +447,8 @@ github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/skema-dev/skema-go v0.0.0-20220427180038-06103d6faceb h1:9sBFkRmMb19ZcWLghi4OeWzW0wc8vxwKHDvZrbv745g= -github.com/skema-dev/skema-go v0.0.0-20220427180038-06103d6faceb/go.mod h1:396A6TkYm98kH458fZwg+HnmPRxNNqrQrWJ2VgbaAN8= +github.com/skema-dev/skema-go v1.0.0 h1:n9uCZcy3BEpJJnpfrQAZ+k040JMRrDoLhFMMeG7c4yk= +github.com/skema-dev/skema-go v1.0.0/go.mod h1:SGdqe02Bdd3MzvbhnDBiFlJ16pXuDIoqcHHjzi2Cmno= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= @@ -474,7 +474,6 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/traefik/yaegi v0.11.3/go.mod h1:RuCwD8/wsX7b6KoQHOaIFUfuH3gQIK4KWnFFmJMw5VA= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/sample/grpc-server/grpc.yaml b/sample/grpc-server/grpc.yml similarity index 100% rename from sample/grpc-server/grpc.yaml rename to sample/grpc-server/grpc.yml diff --git a/test/grpcmux_config/conf/grpc_test.yaml b/test/grpcmux_config/conf/grpc_test.yaml new file mode 100644 index 0000000..70cf594 --- /dev/null +++ b/test/grpcmux_config/conf/grpc_test.yaml @@ -0,0 +1,6 @@ +port: 9991 # for grpc service +http: + port: 9992 # for http service + gateway: + path: "/" # this is the routing prefix if you need. You can force to append an extra path before all standard URLs + diff --git a/test/grpcmux_config/grpcmux_config.go b/test/grpcmux_config/grpcmux_config.go new file mode 100644 index 0000000..f34a472 --- /dev/null +++ b/test/grpcmux_config/grpcmux_config.go @@ -0,0 +1,62 @@ +package main + +import ( + "context" + "fmt" + + _ "embed" + + "github.com/skema-dev/skema-go/grpcmux" + "github.com/skema-dev/skema-go/logging" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +func main() { + grpcSrv := grpcmux.NewServer( + grpc.ChainUnaryInterceptor(Interceptor1(), Interceptor2(), Interceptor3()), + ) + + if err := grpcSrv.Serve(); err != nil { + logging.Fatalf("Serve error %v", err.Error()) + } +} + +func Interceptor1() grpc.UnaryServerInterceptor { + return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler) (resp interface{}, err error) { + _, ok := metadata.FromIncomingContext(ctx) + if !ok { + return nil, fmt.Errorf("couldn't parse incoming context metadata") + } + logging.Infof("first interceptoer 11111") + h, err := handler(ctx, req) + return h, err + } +} + +func Interceptor2() grpc.UnaryServerInterceptor { + return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler) (resp interface{}, err error) { + _, ok := metadata.FromIncomingContext(ctx) + if !ok { + return nil, fmt.Errorf("couldn't parse incoming context metadata") + } + logging.Infof(" interceptoer 222222") + h, err := handler(ctx, req) + return h, err + } +} + +func Interceptor3() grpc.UnaryServerInterceptor { + return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler) (resp interface{}, err error) { + _, ok := metadata.FromIncomingContext(ctx) + if !ok { + return nil, fmt.Errorf("couldn't parse incoming context metadata") + } + logging.Infof(" interceptoer 333333") + h, err := handler(ctx, req) + return h, err + } +}