convert url to string

This commit is contained in:
Fabricio 2018-09-07 13:41:24 -03:00
parent 927cc5c348
commit a5f77f7913
3 changed files with 8 additions and 12 deletions

View file

@ -20,7 +20,6 @@ For ready-to-use executables for *Windows*, *Linux* and *Mac*, see [Releases](ht
| `-port` | Set the proxy port. Default: *9000* |
| `-dashboard` | Set the dashboard's name. Default: *dashboard* |
| `-max-captures` | Set the max number of captures to show in the dashboard. Default: *16* |
| `-h` | Show help |
## Using

16
args.go
View file

@ -1,15 +1,12 @@
package main
import (
"flag"
"net/url"
)
import "flag"
type Args struct {
TargetURL *url.URL `json:"targetURL"`
ProxyPort string `json:"proxyPort"`
Dashboard string `json:"dashboard"`
MaxCaptures int `json:"maxCaptures"`
TargetURL string `json:"targetURL"`
ProxyPort string `json:"proxyPort"`
Dashboard string `json:"dashboard"`
MaxCaptures int `json:"maxCaptures"`
}
func ParseArgs() Args {
@ -18,6 +15,5 @@ func ParseArgs() Args {
dashboard := flag.String("dashboard", "dashboard", "Set the dashboard name")
maxCaptures := flag.Int("max-captures", 16, "Set the max number of captures to show in the dashboard")
flag.Parse()
url, _ := url.Parse(*targetURL)
return Args{url, *proxyPort, *dashboard, *maxCaptures}
return Args{*targetURL, *proxyPort, *dashboard, *maxCaptures}
}

View file

@ -95,7 +95,8 @@ func getDashboardItemInfoHandler() http.Handler {
})
}
func getProxyHandler(url *url.URL, transp *transport) http.Handler {
func getProxyHandler(targetURL string, transp *transport) http.Handler {
url, _ := url.Parse(targetURL)
proxy := httputil.NewSingleHostReverseProxy(url)
proxy.Transport = transp
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {