Skip to content
Permalink
Browse files
fix: contxt
  • Loading branch information
PhilYue committed Dec 5, 2021
1 parent 947e944 commit f6049278c539a9bffe0d4a435dd34d6cee0a2cbd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
@@ -23,6 +23,8 @@ import (

type (

ContextKey string

// Context run context
Context interface {
Next()
@@ -51,3 +53,7 @@ type (
Response()
}
)

func (c ContextKey) String() string {
return string(c)
}
@@ -20,6 +20,7 @@ package grpcproxy
import (
"context"
"fmt"
cnt "github.com/apache/dubbo-go-pixiu/pkg/context"
"github.com/apache/dubbo-go-pixiu/pkg/logger"
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/desc/protoparse"
@@ -41,7 +42,7 @@ type Descriptor struct {
fileSource *fileSource
}

func (dr *Descriptor) GetCurrentDescriptor(ctx context.Context) (DescriptorSource, error) {
func (dr *Descriptor) GetCurrentDescriptorSource(ctx context.Context) (DescriptorSource, error) {

value := ctx.Value(DescriptorSourceKey)

@@ -70,7 +71,7 @@ func (dr *Descriptor) getDescriptorSource(ctx context.Context, cfg *Config) (Des
case REMOTE:
// server reflection only
var cc *grpc.ClientConn
gconn := ctx.Value(GrpcClientConnKey)
gconn := ctx.Value(cnt.ContextKey(GrpcClientConnKey))
switch t := gconn.(type) {
case *grpc.ClientConn:
cc = gconn.(*grpc.ClientConn)
@@ -92,9 +93,7 @@ func (dr *Descriptor) getDescriptorSource(ctx context.Context, cfg *Config) (Des
err = errors.Errorf("grpc descriptor source not initialized cause the config of `descriptor_source_strategy` is %s, maybe set it `AUTO`", cfg.DescriptorSourceStrategy)
}

if err == nil {
context.WithValue(ctx, DescriptorSourceKey, ds)
}
// ctx = context.WithValue(ctx, ct.ContextKey(DescriptorSourceKey), source)

return ds, err
}
@@ -47,6 +47,7 @@ import (
import (
"github.com/apache/dubbo-go-pixiu/pkg/common/constant"
"github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
ct "github.com/apache/dubbo-go-pixiu/pkg/context"
"github.com/apache/dubbo-go-pixiu/pkg/context/http"
"github.com/apache/dubbo-go-pixiu/pkg/logger"
"github.com/apache/dubbo-go-pixiu/pkg/server"
@@ -196,7 +197,7 @@ func (f *Filter) Handle(c *http.HttpContext) {
}

// get DescriptorSource, contain file and reflection
source, err := f.getDescriptorSource(context.WithValue(c.Ctx, GrpcClientConnKey, clientConn), f.cfg)
source, err := f.getDescriptorSource(context.WithValue(c.Ctx, ct.ContextKey(GrpcClientConnKey), clientConn), f.cfg)
if err != nil {
logger.Errorf("%s err %s : %s ", loggerHeader, "get desc source fail", err)
c.Err = perrors.New("service not config proto file or the server not support reflection API")

0 comments on commit f604927

Please sign in to comment.