forked from yeqown/fasthttp-reverse-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
30 lines (24 loc) · 571 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"log"
"github.com/valyala/fasthttp"
proxy "github.com/adelyte/fasthttp-reverse-proxy/v2"
)
var (
weights = map[string]proxy.Weight{
"localhost:9090": 20,
"localhost:9091": 30,
"localhost:9092": 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)
}
}