Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A reverse proxy in Golang using Gin
package main
import (
func proxy(c *gin.Context) {
remote, err := url.Parse("")
if err != nil {
proxy := httputil.NewSingleHostReverseProxy(remote)
proxy.Director = func(req *http.Request) {
req.Header = c.Request.Header
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()
r.Any("/*proxyPath", proxy)
Copy link

hoiama commented Jul 22, 2022

Thank you very very much to your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment