changing the server port to flag
[VSCPweb/.git] / vscpweb.go
index f27e55aa17b7fa480f5258e3b509657ca38b6ead..24be89304d13238d97376c04a11f259d6a4f92b9 100644 (file)
@@ -4,9 +4,12 @@
 package main
 
 import (
+       "flag"
        "fmt"
        "html/template"
+       "math/rand"
        "net/http"
+       "strconv"
 
        hh "healthHandlers"
        //mh "managementHandlers"
@@ -28,7 +31,12 @@ func main() {
        s.Router.Handle("/static/*", http.StripPrefix("/static/", fs))
 
        //staring up the server:
-       http.ListenAndServe(":8001", s.Router)
+       port := flag.Int("port", 8001, "Port in which the server will be started")
+       flag.Parse()
+       setPort := strconv.Itoa(*port)
+       setPort = ":" + setPort
+
+       http.ListenAndServe(setPort, s.Router)
 }
 
 type server struct {
@@ -134,8 +142,11 @@ func (s *server) MountHandlers() {
 
 // GenericHandler404 is the universal 404 response of this front end
 func GenericHandler404(w http.ResponseWriter, r *http.Request) {
+
        w.WriteHeader(404)
-       w.Write([]byte("route does not exist"))
+       messages := []string{"route does not exist", "page not found", "resource not found"}
+       randomIndex := rand.Intn(len(messages))
+       w.Write([]byte(messages[randomIndex]))
 }
 
 // GenericHandler405 is the universal 405 response of this front end
@@ -152,9 +163,9 @@ func ExampleHandler(w http.ResponseWriter, r *http.Request) {
 
 func indexHandler(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusOK)
-       passarg := "some passing argument"
+       passarg := "some passing argument done"
        indexTemplate := template.Must(template.ParseFiles("templates/views/index.html"))
-    //check for go partial templates so you can extract blocks you want to use
+       //check for go partial templates so you can extract blocks you want to use
        indexTemplate.Execute(w, passarg)
 
 }