任何人都可以將Golang的ReverseProxy功能與Iris-Go Web框架聯繫起來。我不能讓它工作。我可以用普通的net/http連接它。帶有Iris-Go框架的Golang ReverseProxy
func MultiHostReverseProxy(targets map[string]utils.Service) *httputil.ReverseProxy {
r := regexp.MustCompile(`\/proxy/(?P<Service>[a-zA-Z_-]*)(?P<Path>\/.*)`)
director := func(req *http.Request) {
if strings.HasPrefix(req.URL.Path, "/proxy/") {
temp := r.FindStringSubmatch(req.URL.Path);
if (len(temp) > 1) {
system := temp[1]
if val, ok := targets[system]; ok {
s := val.Host + ":" + val.Port
req.URL.Scheme = val.Scheme
req.URL.Host = s
req.URL.Path = temp[2]
if enc, ok := GetAxleHeader(req.Header); ok {
dec := utils.Decrypt(KEY, enc)
req.Header.Set(val.AuthHeader, dec)
req.Header.Set(AXLE_HEADER, "")
} else {
token, nq := utils.FindAxleToken(req.URL.RawQuery);
fmt.Printf("%s -> token : %s newQuery: %s\n", req.URL.RawQuery, token, nq);
if token != "" {
req.URL.RawQuery = nq
dec := utils.Decrypt(KEY, token)
req.Header.Set(val.AuthHeader, dec)
req.Header.Set(AXLE_HEADER, "")
}
}
}
}
}
}
return &httputil.ReverseProxy{Director: director}
}
如何在虹膜框架中使用此ReverseProxy對象;
我不明白爲什麼有人使用虹膜http://www.florinpatan.ro/2016/10/why-you-should-not-use-iris-for-your-go.html?m=1 – JimB
你不能使用httputi l反向代理,因爲iris不使用std lib net/http軟件包。 – JimB
@JimB在版本5之後,Iris構建在net/http之上,以完成其HTTP/2功能。 – kataras