Documentation ¶
Overview ¶
Example ¶
This example create several reverse proxy to show how to use proxy middleware. We proxy three path to `api.bilibili.com` and return response without any changes.
package main import ( "go-common/library/net/http/blademaster" "go-common/library/net/http/blademaster/middleware/proxy" ) func main() { proxies := map[string]string{ "/index": "http://api.bilibili.com/html/index", "/ping": "http://api.bilibili.com/api/ping", "/api/versions": "http://api.bilibili.com/api/web/versions", } engine := blademaster.Default() for path, ep := range proxies { engine.GET(path, proxy.NewAlways(ep)) } engine.Run(":18080") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewZoneProxy ¶
func NewZoneProxy(matchZone, dst string) bm.HandlerFunc
NewZoneProxy is
Example ¶
This example create several reverse proxy to show how to use jd proxy middleware. The request will be proxied to destination only when request is from specified datacenter.
package main import ( "go-common/library/net/http/blademaster" "go-common/library/net/http/blademaster/middleware/proxy" ) func main() { proxies := map[string]string{ "/index": "http://api.bilibili.com/html/index", "/ping": "http://api.bilibili.com/api/ping", "/api/versions": "http://api.bilibili.com/api/web/versions", } engine := blademaster.Default() // proxy to specified destination for path, ep := range proxies { engine.GET(path, proxy.NewZoneProxy("sh004", ep), func(ctx *blademaster.Context) { ctx.String(200, "Origin") }) } // proxy with request path ug := engine.Group("/update", proxy.NewZoneProxy("sh004", "http://sh001-api.bilibili.com")) ug.POST("/name", func(ctx *blademaster.Context) { ctx.String(500, "Should not be accessed") }) ug.POST("/sign", func(ctx *blademaster.Context) { ctx.String(500, "Should not be accessed") }) engine.Run(":18080") }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.