Skip to content

Instantly share code, notes, and snippets.

@simon-cj
Created July 1, 2020 03:35
Show Gist options
  • Save simon-cj/b4da0b2bca793ec3b8a5abe04c8fca41 to your computer and use it in GitHub Desktop.
Save simon-cj/b4da0b2bca793ec3b8a5abe04c8fca41 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/base64"
"net/http"
"net/http/httputil"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
)
func reverseProxy(c *context.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.ResponseWriter, c.Request)
}
func startServer() {
beego.Any("/api/v2.0/projects", reverseProxy)
beego.Run(":8888")
}
func main() {
startServer()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment