新增 DefaultTimeout、DefaultRetry常量

This commit is contained in:
zhangzeyi
2023-03-15 17:55:51 +08:00
parent 28ee128a6d
commit f148a46d1b
6 changed files with 23 additions and 11 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ package dubbo2_to_http
import (
"github.com/eolinker/apinto/drivers"
"github.com/eolinker/apinto/entries/ctx_key"
"github.com/eolinker/apinto/entries/router"
"github.com/eolinker/eosc"
"github.com/eolinker/eosc/eocontext"
dubbo2_context "github.com/eolinker/eosc/eocontext/dubbo2-context"
@@ -25,13 +26,13 @@ func (t *ToHttp) DoDubboFilter(ctx dubbo2_context.IDubbo2Context, next eocontext
retryValue := ctx.Value(ctx_key.CtxKeyRetry)
retry, ok := retryValue.(int)
if !ok {
retry = 0
retry = router.DefaultRetry
}
timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout)
timeout, ok := timeoutValue.(time.Duration)
if !ok {
timeout = 3000 * time.Millisecond
timeout = router.DefaultTimeout
}
complete := NewComplete(retry, timeout, t.contentType, t.path, t.method, t.params)
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/eolinker/apinto/entries/ctx_key"
"github.com/eolinker/apinto/entries/router"
"net/url"
"strings"
"time"
@@ -66,13 +67,13 @@ func (h *complete) Complete(org eocontext.EoContext) error {
retryValue := ctx.Value(ctx_key.CtxKeyRetry)
retry, ok := retryValue.(int)
if !ok {
retry = 0
retry = router.DefaultRetry
}
timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout)
timeout, ok := timeoutValue.(time.Duration)
if !ok {
timeout = defaultTimeout
timeout = router.DefaultTimeout
}
descriptor, err := h.descriptor.Descriptor().FindSymbol(fmt.Sprintf("%s.%s", ctx.Proxy().Service(), ctx.Proxy().Method()))
+3 -2
View File
@@ -3,6 +3,7 @@ package http_to_dubbo2
import (
"github.com/eolinker/apinto/drivers"
"github.com/eolinker/apinto/entries/ctx_key"
"github.com/eolinker/apinto/entries/router"
"github.com/eolinker/eosc"
"github.com/eolinker/eosc/eocontext"
http_context "github.com/eolinker/eosc/eocontext/http-context"
@@ -24,13 +25,13 @@ func (p *ToDubbo2) DoHttpFilter(ctx http_context.IHttpContext, next eocontext.IC
retryValue := ctx.Value(ctx_key.CtxKeyRetry)
retry, ok := retryValue.(int)
if !ok {
retry = 1
retry = router.DefaultRetry
}
timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout)
timeout, ok := timeoutValue.(time.Duration)
if !ok {
timeout = 3000 * time.Millisecond
timeout = router.DefaultTimeout
}
complete := NewComplete(retry, timeout, p.service, p.method, p.params)
+3 -3
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/eolinker/apinto/entries/ctx_key"
"github.com/eolinker/apinto/entries/router"
"net/http"
"strings"
"time"
@@ -38,7 +39,6 @@ var (
options = grpcurl.FormatOptions{
AllowUnknownFields: true,
}
defaultTimeout = 10 * time.Second
)
type complete struct {
@@ -91,13 +91,13 @@ func (h *complete) Complete(org eocontext.EoContext) error {
retryValue := ctx.Value(ctx_key.CtxKeyRetry)
retry, ok := retryValue.(int)
if !ok {
retry = 1
retry = router.DefaultRetry
}
timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout)
timeout, ok := timeoutValue.(time.Duration)
if !ok {
timeout = defaultTimeout
timeout = router.DefaultTimeout
}
in := strings.NewReader(string(body))
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/eolinker/apinto/entries/ctx_key"
"github.com/eolinker/apinto/entries/router"
"strconv"
"strings"
"time"
@@ -59,13 +60,13 @@ func (h *HttpComplete) Complete(org eocontext.EoContext) error {
retryValue := ctx.Value(ctx_key.CtxKeyRetry)
retry, ok := retryValue.(int)
if !ok {
retry = 1
retry = router.DefaultRetry
}
timeoutValue := ctx.Value(ctx_key.CtxKeyTimeout)
timeout, ok := timeoutValue.(time.Duration)
if !ok {
timeout = 3000 * time.Millisecond
timeout = router.DefaultTimeout
}
for index := 0; index <= retry; index++ {
+8
View File
@@ -0,0 +1,8 @@
package router
import "time"
const (
DefaultRetry = 0
DefaultTimeout = time.Second * 30
)