package main import ( "flag" "fmt" "log" "net/http" "github.com/gorilla/mux" ) func homePage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Nothing here...") } func handleRequests(runmode string) { // creates a new instance of a mux router router := mux.NewRouter().StrictSlash(true) // replace http.HandleFunc with myRouter.HandleFunc router.HandleFunc("/", homePage) router.HandleFunc("/commands", commands) router.HandleFunc("/response", response) if runmode == "reg" { router.HandleFunc("/register", register) } // serve the router log.Fatal(http.ListenAndServe(":10000", router)) } func main() { // Flags registerPtr := flag.Bool("register", false, "allow new clients to register with the server") // parse all flags flag.Parse() if *registerPtr == true { log.Println("Starting the server in registration mode...") handleRequests("reg") } else { log.Println("Starting the server...") handleRequests("") } // start server }