proxy
Proxy中间件,可以将指定的请求转发至另外的服务,并可重写url。
Example
package main
import (
"net/url"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
target, _ := url.Parse("https://www.baidu.com")
e.GET("/*", middleware.NewProxy(middleware.ProxyConfig{
// proxy done will call this function
Done: func(c *elton.Context) {
},
// http request url rewrite
Rewrites: []string{
"/api/*:/$1",
},
Target: target,
// change the request host
Host: "www.baidu.com",
}))
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}