mirror of
https://gitee.com/johng/gf
synced 2026-06-18 14:27:31 +08:00
change parameter prefix of type string to prefixes of type slice for command enums (#2662)
This commit is contained in:
@ -18,7 +18,7 @@ const (
|
||||
// StartServer1 starts Server1: A simple http server for demo.
|
||||
func StartServer1() {
|
||||
s := g.Server(1)
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
s.BindHandler("/*", func(r *ghttp.Request) {
|
||||
r.Response.Write("response from server 1")
|
||||
})
|
||||
s.BindHandler("/user/1", func(r *ghttp.Request) {
|
||||
@ -33,11 +33,17 @@ func StartServer1() {
|
||||
func StartServer2() {
|
||||
s := g.Server(2)
|
||||
u, _ := url.Parse(UpStream)
|
||||
s.BindHandler("/*", func(r *ghttp.Request) {
|
||||
proxy := httputil.NewSingleHostReverseProxy(u)
|
||||
proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) {
|
||||
writer.WriteHeader(http.StatusBadGateway)
|
||||
}
|
||||
proxy := httputil.NewSingleHostReverseProxy(u)
|
||||
proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) {
|
||||
writer.WriteHeader(http.StatusBadGateway)
|
||||
}
|
||||
s.BindHandler("/proxy/*url", func(r *ghttp.Request) {
|
||||
var (
|
||||
originalPath = r.Request.URL.Path
|
||||
proxyToPath = "/" + r.Get("url").String()
|
||||
)
|
||||
r.Request.URL.Path = proxyToPath
|
||||
g.Log().Infof(r.Context(), `server2:"%s" -> server1:"%s"`, originalPath, proxyToPath)
|
||||
proxy.ServeHTTP(r.Response.Writer.RawWriter(), r.Request)
|
||||
})
|
||||
s.SetPort(PortOfServer2)
|
||||
|
||||
Reference in New Issue
Block a user