server/main.go

48 lines
982 B
Go
Raw Permalink Normal View History

2020-12-11 20:23:16 +00:00
package main
import (
"flag"
2020-12-11 20:34:34 +00:00
"fmt"
2020-12-11 20:23:16 +00:00
"log"
"net/http"
"github.com/gorilla/mux"
)
2020-12-11 20:34:34 +00:00
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Nothing here...")
}
2020-12-11 20:23:16 +00:00
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
}