Skip to content

Commit

Permalink
#2469 gateway转发时间配置化
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjiawei committed Nov 20, 2024
1 parent c7c8159 commit 09e2961
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion platform-gateway/api/support/redirect_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httputil"
"strings"
"time"

"github.com/WeBankPartners/wecube-platform/platform-gateway/common/log"
"github.com/WeBankPartners/wecube-platform/platform-gateway/model"
Expand Down Expand Up @@ -44,7 +45,12 @@ func (invoke RedirectInvoke) Do(c *gin.Context) error {
newRequest.URL.RawQuery = cloneRequest.URL.RawQuery
//auth.SetRequestSourceAuth(newRequest, config.Config.Auth.Source.AppId, config.Config.Auth.Source.PrivateKeyBytes)

client := &http.Client{}
client := &http.Client{
Timeout: 30 * time.Minute,
}
if model.Config.ProxyConfig.Timeout > 0 {
client.Timeout = time.Duration(model.Config.Remote.Timeout) * time.Minute
}
if strings.EqualFold(model.Config.Log.Level, "debug") {
requestDump, _ := httputil.DumpRequest(newRequest, true)
log.Logger.Debug("Request to downstream system: " + string(requestDump))
Expand Down
5 changes: 4 additions & 1 deletion platform-gateway/build/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"context": "auth",
"target_path": "http://[#AUTH_SERVER_ADDRESS]"
}
]
],
"proxy_config": {
"timeout":[#GATEWAY_PROXY_CONFIG]
}
}
1 change: 1 addition & 0 deletions platform-gateway/build/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ sed -i "s~\[#GATEWAY_ROUTE_CONFIG_SERVER\]~$GATEWAY_ROUTE_CONFIG_SERVER~g" /app/
sed -i "s~\[#GATEWAY_ROUTE_CONFIG_URI\]~$GATEWAY_ROUTE_CONFIG_URI~g" /app/platform-gateway/config/default.json
sed -i "s~\[#WECUBE_CORE_ADDRESS\]~$WECUBE_CORE_ADDRESS~g" /app/platform-gateway/config/default.json
sed -i "s~\[#AUTH_SERVER_ADDRESS\]~$AUTH_SERVER_ADDRESS~g" /app/platform-gateway/config/default.json
sed -i "s~\[#GATEWAY_PROXY_CONFIG\]~$GATEWAY_PROXY_CONFIG~g" /app/platform-gateway/config/default.json

exec ./platform-gateway
1 change: 1 addition & 0 deletions platform-gateway/docker-compose.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ services:
- GATEWAY_ROUTE_CONFIG_URI=[#GATEWAY_ROUTE_CONFIG_URI]
- WECUBE_CORE_ADDRESS=[#WECUBE_CORE_ADDRESS]
- AUTH_SERVER_ADDRESS=[#AUTH_SERVER_ADDRESS]
- GATEWAY_PROXY_CONFIG=[#GATEWAY_PROXY_CONFIG]
5 changes: 5 additions & 0 deletions platform-gateway/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type RemoteServiceConfig struct {
Timeout int `json:"timeout"`
}

type ProxyConfig struct {
Timeout int `json:"timeout"`
}

type RedirectRoute struct {
Context string `json:"context"`
TargetPath string `json:"target_path"`
Expand All @@ -45,6 +49,7 @@ type GlobalConfig struct {
Log LogConfig `json:"log"`
Database DatabaseConfig `json:"database"`
Remote RemoteServiceConfig `json:"remote_service"`
ProxyConfig ProxyConfig `json:"proxy_config"`
RedirectRoutes []RedirectRoute `json:"redirect_routes"`
}

Expand Down

0 comments on commit 09e2961

Please sign in to comment.