mirror of
https://github.com/eolinker/apinto
synced 2026-04-23 00:17:04 +08:00
新增 DefaultTimeout、DefaultRetry常量
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,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)
|
||||
|
||||
@@ -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++ {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package router
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
DefaultRetry = 0
|
||||
DefaultTimeout = time.Second * 30
|
||||
)
|
||||
Reference in New Issue
Block a user