Spaces:
Running
Running
package main | |
import ( | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"github.com/gin-gonic/gin" | |
) | |
func proxy(c *gin.Context) { | |
remote, err := url.Parse("http://146.190.67.151") | |
if err != nil { | |
panic(err) | |
} | |
proxy := httputil.NewSingleHostReverseProxy(remote) | |
//Define the director func | |
//This is a good place to log, for example | |
proxy.Director = func(req *http.Request) { | |
req.Host = remote.Host | |
req.URL.Scheme = remote.Scheme | |
req.URL.Host = remote.Host | |
req.URL.Path = c.Param("proxyPath") | |
} | |
proxy.ServeHTTP(c.Writer, c.Request) | |
} | |
func main() { | |
r := gin.Default() | |
//Create a catchall route | |
r.Any("/*proxyPath", proxy) | |
r.Run(":7860") | |
} | |