添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
宽容的毛衣  ·  地运与入囚-北京公墓网·  3 周前    · 
淡定的米饭  ·  杭州AP国际学校|| ...·  4 周前    · 
读研的键盘  ·  Global Wage Report ...·  2 月前    · 

Proxy

Proxy provides an HTTP/WebSocket reverse proxy middleware. It forwards a request to upstream server using a configured load balancing technique.

Usage

url1, err := url.Parse("http://localhost:8081")
if err != nil {
e.Logger.Fatal(err)
}
url2, err := url.Parse("http://localhost:8082")
if err != nil {
e.Logger.Fatal(err)
}
e.Use(middleware.Proxy(middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{
{
URL: url1,
},
{
URL: url2,
},
})))

Custom Configuration

Usage

e := echo.New()
e.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{}))

Configuration

// ProxyConfig defines the config for Proxy middleware.
ProxyConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper

// Balancer defines a load balancing technique.
// Required.
Balancer ProxyBalancer

// Rewrite defines URL path rewrite rules. The values captured in asterisk can be
// retrieved by index e.g. $1, $2 and so on.
Rewrite map[string]string

// RegexRewrite defines rewrite rules using regexp.Rexexp with captures
// Every capture group in the values can be retrieved by index e.g. $1, $2 and so on.
RegexRewrite map[*regexp.Regexp]string

// Context key to store selected ProxyTarget into context.
// Optional. Default value "target".
ContextKey string

// To customize the transport to remote.
// Examples: If custom TLS certificates are required.
Transport http.RoundTripper

// ModifyResponse defines function to modify response from ProxyTarget.
ModifyResponse func(*http.Response) error

Default Configuration

Name Value
Skipper DefaultSkipper
ContextKey target

Regex-based Rules

For advanced rewriting of proxy requests rules may also be defined using