43 lines
881 B
Go
43 lines
881 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
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
|
|
}
|