(serverAddr string, transport http.RoundTripper, pathToExclude string)
| 41 | } |
| 42 | |
| 43 | func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclude string) (*httputil.ReverseProxy, error) { |
| 44 | target, err := url.Parse(serverAddr) |
| 45 | if err != nil { |
| 46 | log.Println(err) |
| 47 | return nil, err |
| 48 | } |
| 49 | proxy := httputil.NewSingleHostReverseProxy(target) |
| 50 | proxy.Transport = transport |
| 51 | proxy.Director = func(request *http.Request) { |
| 52 | path := request.URL.Path |
| 53 | request.URL.Host = target.Host |
| 54 | request.URL.Scheme = target.Scheme |
| 55 | request.URL.Path = rewriteRequestUrl(path, pathToExclude) |
| 56 | fmt.Printf("%s\n", request.URL.Path) |
| 57 | } |
| 58 | return proxy, nil |
| 59 | } |
| 60 | |
| 61 | func rewriteRequestUrl(path string, pathToExclude string) string { |
| 62 | parts := strings.Split(path, "/") |
no test coverage detected
searching dependent graphs…