@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "flag"
56 "fmt"
67 "log"
78 "net/http"
@@ -15,30 +16,38 @@ import (
1516)
1617
1718func main () {
18- proxyAddr := "127.0.0.1:8124"
19+ proxyAddr := flag .String ("addr" , "127.0.0.1:8124" ,
20+ "Listen on this address for reverse proxy requests" )
1921
20- if len ( os . Args ) != 2 {
22+ flag . Usage = func () {
2123 fmt .Fprintf (os .Stderr ,
22- "Usage: %s UPSTREAM_URL\n " +
24+ "Usage: %s [flags] UPSTREAM_URL\n " +
2325 "Example: %s https://proxy-dev.example.com\n \n " +
2426 "Note: The oauth2_proxy running at UPSTREAM_URL must be configured with a\n " +
25- " special redirect URL for this development proxy.\n " ,
27+ " special redirect URL for this development proxy.\n \n " ,
2628 os .Args [0 ], os .Args [0 ])
29+ flag .PrintDefaults ()
30+ }
31+
32+ flag .Parse ()
33+
34+ if len (flag .Args ()) != 1 {
35+ flag .Usage ()
2736 os .Exit (1 )
2837 }
2938
30- upstreamURL , err := url .Parse (os .Args [ 1 ])
39+ upstreamURL , err := url .Parse (flag .Args ()[ 0 ])
3140 if err != nil {
3241 log .Fatalf ("Failed to parse target URL: %v" , err )
3342 }
3443
3544 authCompleteNotice := fmt .Sprintf ("Authentication complete. You can now use the proxy.\n \n " +
3645 "Proxy URL: http://%s\n " +
37- "Upstream: %s\n \n " , proxyAddr , upstreamURL )
46+ "Upstream: %s\n \n " , * proxyAddr , upstreamURL )
3847
3948 authCookie := authenticate (upstreamURL , authCompleteNotice )
4049
41- go runProxy (proxyAddr , upstreamURL , authCookie )
50+ go runProxy (* proxyAddr , upstreamURL , authCookie )
4251
4352 log .Printf ("The proxy will automatically terminate in 12 hours (reauthentication required)" )
4453
0 commit comments