代码拉取完成,页面将自动刷新
reverse http proxy handler based on fasthttp.
HTTP
reverse proxy based fasthttp
httputil.ReverseProxy
library.fasthttp.HostClient
rounddobin
HostClient
object pool with an overlay of fasthttp connection pool.WebSocket
reverse proxy.var (
proxyServer = proxy.NewReverseProxy("localhost:8080")
// use with balancer
// weights = map[string]proxy.Weight{
// "localhost:8080": 20,
// "localhost:8081": 30,
// "localhost:8082": 50,
// }
// proxyServer = proxy.NewReverseProxy("", proxy.WithBalancer(weights))
)
// ProxyHandler ... fasthttp.RequestHandler func
func ProxyHandler(ctx *fasthttp.RequestCtx) {
// all proxy to localhost
proxyServer.ServeHTTP(ctx)
}
func main() {
if err := fasthttp.ListenAndServe(":8081", ProxyHandler); err != nil {
log.Fatal(err)
}
}
var (
proxyServer *proxy.WSReverseProxy
once sync.Once
)
// ProxyHandler ... fasthttp.RequestHandler func
func ProxyHandler(ctx *fasthttp.RequestCtx) {
once.Do(func() {
var err error
proxyServer, err = proxy.NewWSReverseProxyWith(
proxy.WithURL_OptionWS("ws://localhost:8080/echo"),
// [OPTIONAL]: you can override path from `WithURL_OptionWS`
// by providing WithDynamicPath_OptionWS.
proxy.WithDynamicPath_OptionWS(true, proxy.DefaultOverrideHeader),
)
if err != nil {
panic(err)
}
})
switch string(ctx.Path()) {
case "/echo":
// [OPTIONAL]: you can override path from `WithURL_OptionWS`
// by providing proxy.DefaultOverrideHeader (or any custom) header
// ctx.Request.Header.Set(proxy.DefaultOverrideHeader, "/real_echo")
proxyServer.ServeHTTP(ctx)
case "/":
fasthttp.ServeFileUncompressed(ctx, "./index.html")
default:
ctx.Error("Unsupported path", fasthttp.StatusNotFound)
}
}
func main() {
log.Println("serving on: 8081")
if err := fasthttp.ListenAndServe(":8081", ProxyHandler); err != nil {
log.Fatal(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。