diff --git a/drivers/plugins/dubbo2-to-http/to-http.go b/drivers/plugins/dubbo2-to-http/to-http.go index 08794386..47291f03 100644 --- a/drivers/plugins/dubbo2-to-http/to-http.go +++ b/drivers/plugins/dubbo2-to-http/to-http.go @@ -2,6 +2,7 @@ package dubbo2_to_http import ( "github.com/eolinker/apinto/drivers" + "github.com/eolinker/apinto/entries/ctx_key" "github.com/eolinker/eosc" "github.com/eolinker/eosc/eocontext" dubbo2_context "github.com/eolinker/eosc/eocontext/dubbo2-context" @@ -21,13 +22,13 @@ type ToHttp struct { func (t *ToHttp) DoDubboFilter(ctx dubbo2_context.IDubbo2Context, next eocontext.IChain) (err error) { - retryValue := ctx.Value(eocontext.CtxKeyRetry) + retryValue := ctx.Value(ctx_key.CtxKeyRetry) retry, ok := retryValue.(int) if !ok { retry = 0 } - timeoutValue := ctx.Value(eocontext.CtxKeyTimeout) + timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout) timeout, ok := timeoutValue.(time.Duration) if !ok { timeout = 3000 * time.Millisecond diff --git a/drivers/plugins/gRPC-to-http/complete.go b/drivers/plugins/gRPC-to-http/complete.go index 4bab4c83..22bb7703 100644 --- a/drivers/plugins/gRPC-to-http/complete.go +++ b/drivers/plugins/gRPC-to-http/complete.go @@ -3,6 +3,7 @@ package grpc_to_http import ( "errors" "fmt" + "github.com/eolinker/apinto/entries/ctx_key" "net/url" "strings" "time" @@ -62,13 +63,13 @@ func (h *complete) Complete(org eocontext.EoContext) error { return err } - retryValue := ctx.Value(eocontext.CtxKeyRetry) + retryValue := ctx.Value(ctx_key.CtxKeyRetry) retry, ok := retryValue.(int) if !ok { retry = 0 } - timeoutValue := ctx.Value(eocontext.CtxKeyTimeout) + timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout) timeout, ok := timeoutValue.(time.Duration) if !ok { timeout = defaultTimeout diff --git a/drivers/plugins/http-to-dubbo2/to-dubbo2.go b/drivers/plugins/http-to-dubbo2/to-dubbo2.go index e0cd20a7..3bb95d5c 100644 --- a/drivers/plugins/http-to-dubbo2/to-dubbo2.go +++ b/drivers/plugins/http-to-dubbo2/to-dubbo2.go @@ -2,6 +2,7 @@ package http_to_dubbo2 import ( "github.com/eolinker/apinto/drivers" + "github.com/eolinker/apinto/entries/ctx_key" "github.com/eolinker/eosc" "github.com/eolinker/eosc/eocontext" http_context "github.com/eolinker/eosc/eocontext/http-context" @@ -20,13 +21,13 @@ type ToDubbo2 struct { func (p *ToDubbo2) DoHttpFilter(ctx http_context.IHttpContext, next eocontext.IChain) error { - retryValue := ctx.Value(eocontext.CtxKeyRetry) + retryValue := ctx.Value(ctx_key.CtxKeyRetry) retry, ok := retryValue.(int) if !ok { retry = 1 } - timeoutValue := ctx.Value(eocontext.CtxKeyTimeout) + timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout) timeout, ok := timeoutValue.(time.Duration) if !ok { timeout = 3000 * time.Millisecond diff --git a/drivers/plugins/http-to-gRPC/complete.go b/drivers/plugins/http-to-gRPC/complete.go index 2bd98f1a..81cdb4f1 100644 --- a/drivers/plugins/http-to-gRPC/complete.go +++ b/drivers/plugins/http-to-gRPC/complete.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "encoding/json" "fmt" + "github.com/eolinker/apinto/entries/ctx_key" "net/http" "strings" "time" @@ -87,13 +88,13 @@ func (h *complete) Complete(org eocontext.EoContext) error { return err } - retryValue := ctx.Value(eocontext.CtxKeyRetry) + retryValue := ctx.Value(ctx_key.CtxKeyRetry) retry, ok := retryValue.(int) if !ok { retry = 1 } - timeoutValue := ctx.Value(eocontext.CtxKeyTimeout) + timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout) timeout, ok := timeoutValue.(time.Duration) if !ok { timeout = defaultTimeout diff --git a/drivers/router/dubbo2-router/handler.go b/drivers/router/dubbo2-router/handler.go index 4b42cb97..d58e688d 100644 --- a/drivers/router/dubbo2-router/handler.go +++ b/drivers/router/dubbo2-router/handler.go @@ -2,6 +2,7 @@ package dubbo2_router import ( "errors" + "github.com/eolinker/apinto/entries/ctx_key" "time" "github.com/eolinker/apinto/drivers/router/dubbo2-router/manager" @@ -41,8 +42,8 @@ func (d *dubboHandler) ServeHTTP(ctx eocontext.EoContext) { } //set retry timeout - ctx.WithValue(eocontext.CtxKeyRetry, d.retry) - ctx.WithValue(eocontext.CtxKeyTimeout, d.timeout) + ctx.WithValue(ctx_key.CtxKeyRetry, d.retry) + ctx.WithValue(ctx_key.CtxKeyTimeout, d.timeout) //Set Label ctx.SetLabel("api", d.routerName) diff --git a/drivers/router/grpc-router/handler.go b/drivers/router/grpc-router/handler.go index bf0b591a..1cd69c1a 100644 --- a/drivers/router/grpc-router/handler.go +++ b/drivers/router/grpc-router/handler.go @@ -2,6 +2,7 @@ package grpc_router import ( "github.com/eolinker/apinto/drivers/router/grpc-router/manager" + "github.com/eolinker/apinto/entries/ctx_key" "github.com/eolinker/apinto/service" grpc_context "github.com/eolinker/eosc/eocontext/grpc-context" "google.golang.org/grpc/codes" @@ -40,8 +41,8 @@ func (h *grpcRouter) ServeHTTP(ctx eocontext.EoContext) { } //set retry timeout - ctx.WithValue(eocontext.CtxKeyRetry, h.retry) - ctx.WithValue(eocontext.CtxKeyTimeout, h.timeout) + ctx.WithValue(ctx_key.CtxKeyRetry, h.retry) + ctx.WithValue(ctx_key.CtxKeyTimeout, h.timeout) //Set Label ctx.SetLabel("api", h.routerName) diff --git a/drivers/router/http-router/http-complete/complete.go b/drivers/router/http-router/http-complete/complete.go index d3c401cc..bf317423 100644 --- a/drivers/router/http-router/http-complete/complete.go +++ b/drivers/router/http-router/http-complete/complete.go @@ -3,6 +3,7 @@ package http_complete import ( "errors" "fmt" + "github.com/eolinker/apinto/entries/ctx_key" "strconv" "strings" "time" @@ -55,13 +56,13 @@ func (h *HttpComplete) Complete(org eocontext.EoContext) error { } timeOut := app.TimeOut() - retryValue := ctx.Value(eocontext.CtxKeyRetry) + retryValue := ctx.Value(ctx_key.CtxKeyRetry) retry, ok := retryValue.(int) if !ok { retry = 1 } - timeoutValue := ctx.Value(eocontext.CtxKeyTimeout) + timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout) timeout, ok := timeoutValue.(time.Duration) if !ok { timeout = 3000 * time.Millisecond diff --git a/drivers/router/http-router/http-handler.go b/drivers/router/http-router/http-handler.go index f9194336..bddd0427 100644 --- a/drivers/router/http-router/http-handler.go +++ b/drivers/router/http-router/http-handler.go @@ -1,6 +1,7 @@ package http_router import ( + "github.com/eolinker/apinto/entries/ctx_key" "net/http" "time" @@ -54,8 +55,8 @@ func (h *httpHandler) ServeHTTP(ctx eocontext.EoContext) { ctx = wsCtx } //set retry timeout - ctx.WithValue(eocontext.CtxKeyRetry, h.retry) - ctx.WithValue(eocontext.CtxKeyTimeout, h.timeout) + ctx.WithValue(ctx_key.CtxKeyRetry, h.retry) + ctx.WithValue(ctx_key.CtxKeyTimeout, h.timeout) //Set Label ctx.SetLabel("api", h.routerName) diff --git a/entries/ctx_key/ctx_key.go b/entries/ctx_key/ctx_key.go new file mode 100644 index 00000000..e34e341b --- /dev/null +++ b/entries/ctx_key/ctx_key.go @@ -0,0 +1,6 @@ +package ctx_key + +const ( + CtxKeyRetry = "retry" + CtxKeyTimeout = "timeout" +) diff --git a/node/http-context/context.go b/node/http-context/context.go index f1acca8a..75bc050b 100644 --- a/node/http-context/context.go +++ b/node/http-context/context.go @@ -3,6 +3,7 @@ package http_context import ( "context" "fmt" + "github.com/eolinker/apinto/entries/ctx_key" "net" "strings" "time" @@ -211,8 +212,8 @@ func (ctx *HttpContext) Clone() (eoscContext.EoContext, error) { //记录请求时间 copyContext.ctx = context.WithValue(ctx.Context(), http_service.KeyCloneCtx, true) - copyContext.WithValue(eoscContext.CtxKeyRetry, 0) - copyContext.WithValue(eoscContext.CtxKeyRetry, time.Duration(0)) + copyContext.WithValue(ctx_key.CtxKeyRetry, 0) + copyContext.WithValue(ctx_key.CtxKeyRetry, time.Duration(0)) return copyContext, nil }