bug_chomper: Make server's port configurable.
authortfarina <tfarina@chromium.org>
Mon, 13 Oct 2014 19:43:01 +0000 (12:43 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 13 Oct 2014 19:43:01 +0000 (12:43 -0700)
Make 'port' a flag so you can change it from the command line, making the
server more flexible and allowing us to change in which port it listen
to requests.

$ ./run_server.sh --port :8002

BUG=None
TEST=see above
R=borenet@google.com

Review URL: https://codereview.chromium.org/649663003

tools/bug_chomper/run_server.sh
tools/bug_chomper/src/server/server.go

index a6cb453..76518af 100755 (executable)
@@ -20,4 +20,3 @@ if [[ ! -f oauth_client_secret.json ]]; then
 fi
 
 GOPATH="$GOPATH:$DIR" go run $DIR/src/server/server.go $@
-
index a20c679..fcd1ccc 100644 (file)
@@ -35,7 +35,6 @@ const (
        issueComment      = "Edited by BugChomper"
        oauthCallbackPath = "/oauth2callback"
        oauthConfigFile   = "oauth_client_secret.json"
-       defaultPort       = 8000
        localHost         = "127.0.0.1"
        maxSessionLen     = time.Duration(3600 * time.Second)
        priorityPrefix    = "Priority-"
@@ -43,6 +42,11 @@ const (
        cookieName        = "BugChomperCookie"
 )
 
+// Flags:
+var (
+       port = flag.String("port", ":8000", "HTTP service address (e.g., ':8000')")
+)
+
 var (
        scheme = "http"
 
@@ -362,17 +366,16 @@ func main() {
        http.HandleFunc("/", handleRoot)
        http.HandleFunc(oauthCallbackPath, handleOAuth2Callback)
        http.Handle("/res/", http.FileServer(http.Dir(curdir)))
-       port := ":" + strconv.Itoa(defaultPort)
-       log.Println("Server is running at " + scheme + "://" + localHost + port)
+       log.Println("Server is running at " + scheme + "://" + localHost + *port)
        var err error
        if public {
                log.Println("WARNING: This server is not secure and should not be made " +
                        "publicly accessible.")
                scheme = "https"
-               err = http.ListenAndServeTLS(port, certFile, keyFile, nil)
+               err = http.ListenAndServeTLS(*port, certFile, keyFile, nil)
        } else {
                scheme = "http"
-               err = http.ListenAndServe(localHost+port, nil)
+               err = http.ListenAndServe(localHost+*port, nil)
        }
        if err != nil {
                log.Println(err.Error())