File tree Expand file tree Collapse file tree 4 files changed +22
-15
lines changed
fasthttp-reverse-proxy-with-bla
fasthttp-reverse-proxy-with-pool Expand file tree Collapse file tree 4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change 44 "log"
55
66 "github.com/valyala/fasthttp"
7+
78 proxy "github.com/yeqown/fasthttp-reverse-proxy/v2"
89)
910
1415 "localhost:9092" : 50 ,
1516 }
1617
17- proxyServer = proxy .NewReverseProxy ( "" , proxy .WithBalancer (weights ))
18+ proxyServer , _ = proxy .NewReverseProxyWith ( proxy .WithBalancer (weights ))
1819)
1920
2021// ProxyHandler ... fasthttp.RequestHandler func
Original file line number Diff line number Diff line change @@ -4,12 +4,12 @@ import (
44 "log"
55
66 "github.com/valyala/fasthttp"
7+
78 proxy "github.com/yeqown/fasthttp-reverse-proxy/v2"
89)
910
1011var (
1112 pool proxy.Pool
12- err error
1313)
1414
1515// ProxyPoolHandler ...
@@ -25,14 +25,17 @@ func ProxyPoolHandler(ctx *fasthttp.RequestCtx) {
2525}
2626
2727func factory (hostAddr string ) (* proxy.ReverseProxy , error ) {
28- p := proxy .NewReverseProxy (hostAddr )
29- return p , nil
28+ return proxy .NewReverseProxyWith (proxy .WithAddress (hostAddr ))
3029}
3130
3231func main () {
3332 initialCap , maxCap := 100 , 1000
33+ var err error
3434 pool , err = proxy .NewChanPool (initialCap , maxCap , factory )
35- if err := fasthttp .ListenAndServe (":8083" , ProxyPoolHandler ); err != nil {
35+ if err != nil {
36+ panic (err )
37+ }
38+ if err = fasthttp .ListenAndServe (":8083" , ProxyPoolHandler ); err != nil {
3639 panic (err )
3740 }
3841}
Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "log"
45 "strings"
56 "time"
67
7- "github.com/yeqown/log"
8-
98 "github.com/valyala/fasthttp"
9+
1010 proxy "github.com/yeqown/fasthttp-reverse-proxy/v2"
1111)
1212
1313var (
14- proxyServer = proxy .NewReverseProxy ( "localhost:8080" , proxy .WithTimeout (5 * time .Second ))
15- proxyServer2 = proxy .NewReverseProxy ( "api-js.mixpanel.com" )
16- proxyServer3 = proxy .NewReverseProxy ( "baidu.com" )
14+ proxyServer , _ = proxy .NewReverseProxyWith ( proxy . WithAddress ( "localhost:8080" ) , proxy .WithTimeout (5 * time .Second ))
15+ proxyServer2 , _ = proxy .NewReverseProxyWith ( proxy . WithAddress ( "api-js.mixpanel.com" ) )
16+ proxyServer3 , _ = proxy .NewReverseProxyWith ( proxy . WithAddress ( "baidu.com" ) )
1717)
1818
1919// ProxyHandler ... fasthttp.RequestHandler func
2020func ProxyHandler (ctx * fasthttp.RequestCtx ) {
2121 requestURI := string (ctx .RequestURI ())
22- log .Info ("requestURI=" , requestURI )
22+ log .Printf ("requestURI=%s \n " , requestURI )
2323
2424 if strings .HasPrefix (requestURI , "/local" ) {
2525 // "/local" path proxy to localhost
Original file line number Diff line number Diff line change 11package main
22
33import (
4- "github.com/yeqown/ log"
4+ "log"
55
66 "github.com/valyala/fasthttp"
7+
78 proxy "github.com/yeqown/fasthttp-reverse-proxy/v2"
89)
910
1011var (
11- proxyServer = proxy .NewReverseProxy ("127.0.0.1:8080" ,
12- proxy .WithTLS ("./selfsigned.crt" , "./selfsigned.key" ))
12+ proxyServer , _ = proxy .NewReverseProxyWith (
13+ proxy .WithAddress ("localhost:8080" ),
14+ proxy .WithTLS ("./selfsigned.crt" , "./selfsigned.key" ),
15+ )
1316)
1417
1518// ProxyHandler ... fasthttp.RequestHandler func
1619func ProxyHandler (ctx * fasthttp.RequestCtx ) {
1720 requestURI := string (ctx .RequestURI ())
18- log .Info ("a request incoming, requestURI=" , requestURI )
21+ log .Printf ("a request incoming, requestURI=%s \n " , requestURI )
1922 proxyServer .ServeHTTP (ctx )
2023}
2124
You can’t perform that action at this time.
0 commit comments