Created
July 1, 2020 03:20
-
-
Save simon-cj/ae08e70fb7d58e8e97797bc9739b354a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"net/http" | |
"net/http/httputil" | |
"github.com/gin-gonic/gin" | |
) | |
func reverseProxy(c *gin.Context) { | |
proxy := httputil.NewSingleHostReverseProxy(c.Request.URL) | |
proxy.Director = func(req *http.Request) { | |
req.Header = c.Request.Header | |
req.Header["Authorization"] = []string{"basic " + base64.StdEncoding.EncodeToString([]byte("admin:Harbor12345"))} | |
req.Host = "harbor.caicloud.com" | |
req.URL.Scheme = "http" | |
req.URL.Host = "harbor.caicloud.com" | |
req.URL.Path = c.Request.URL.Path | |
} | |
proxy.ServeHTTP(c.Writer, c.Request) | |
} | |
func startServer() { | |
r := gin.Default() | |
r.Any("/api/v2.0/projects", reverseProxy) | |
r.Run(":8888") | |
} | |
func main() { | |
startServer() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment