websocket server 已经打开且正常通过测试。
Starting websocket server at localhost:2003
recv: Hello world!
read: websocket: close 1001 (going away)
websocker proxy 启动正常。
Starting httpserver at 127.0.0.1:2002
访问 localhost:2002
127.0.0.1:2002
以及 ip地址 + 2002
均失败,无法打开网页。
报错如下:
http: panic serving 127.0.0.1:51747: cannot create context from nil parent
web socket proxy 源代码:
package main
import (
"github.com/e421083458/gateway_demo/proxy/load_balance"
"github.com/e421083458/gateway_demo/proxy/middleware"
proxy2 "github.com/e421083458/gateway_demo/proxy/proxy"
"log"
"net/http"
)
var (
addr = "127.0.0.1:2002"
)
func main() {
rb := load_balance.LoadBanlanceFactory(load_balance.LbWeightRoundRobin)
rb.Add("http://127.0.0.1:2003", "50")
proxy := proxy2.NewLoadBalanceReverseProxy(&middleware.SliceRouterContext{}, rb)
log.Println("Starting httpserver at " + addr)
log.Fatal(http.ListenAndServe(addr, proxy))
}