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* | | `-port` | Set the proxy port. Default: *9000* |
| `-dashboard` | Set the dashboard's name. Default: *dashboard* | | `-dashboard` | Set the dashboard's name. Default: *dashboard* |
| `-max-captures` | Set the max number of captures to show in the dashboard. Default: *16* | | `-max-captures` | Set the max number of captures to show in the dashboard. Default: *16* |
| `-h` | Show help |
## Using ## Using

16
args.go
View file

@ -1,15 +1,12 @@
package main package main
import ( import "flag"
"flag"
"net/url"
)
type Args struct { type Args struct {
TargetURL *url.URL `json:"targetURL"` TargetURL string `json:"targetURL"`
ProxyPort string `json:"proxyPort"` ProxyPort string `json:"proxyPort"`
Dashboard string `json:"dashboard"` Dashboard string `json:"dashboard"`
MaxCaptures int `json:"maxCaptures"` MaxCaptures int `json:"maxCaptures"`
} }
func ParseArgs() Args { func ParseArgs() Args {
@ -18,6 +15,5 @@ func ParseArgs() Args {
dashboard := flag.String("dashboard", "dashboard", "Set the dashboard name") 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") maxCaptures := flag.Int("max-captures", 16, "Set the max number of captures to show in the dashboard")
flag.Parse() flag.Parse()
url, _ := url.Parse(*targetURL) return Args{*targetURL, *proxyPort, *dashboard, *maxCaptures}
return Args{url, *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 := httputil.NewSingleHostReverseProxy(url)
proxy.Transport = transp proxy.Transport = transp
return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {