From: Josué Rodríguez Date: Tue, 1 Aug 2023 21:59:07 +0000 (+0000) Subject: Merge branch 'master' of https://github.com/josuer08/VSCPweb X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=05f37a6b612c246b3bcc02a221ace6346ed766be;hp=-c;p=VSCPweb%2F.git Merge branch 'master' of https://github.com/josuer08/VSCPweb --- 05f37a6b612c246b3bcc02a221ace6346ed766be diff --combined vscpweb.go index d4c3ad3,f27e55a..a304d5a --- a/vscpweb.go +++ b/vscpweb.go @@@ -4,12 -4,9 +4,12 @@@ package main import ( + "flag" "fmt" "html/template" + "math/rand" "net/http" + "strconv" hh "healthHandlers" //mh "managementHandlers" @@@ -31,12 -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 { @@@ -142,11 -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")) + +w.WriteHeader(404) + 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 @@@ -165,6 -154,7 +165,7 @@@ func indexHandler(w http.ResponseWriter w.WriteHeader(http.StatusOK) passarg := "some passing argument" indexTemplate := template.Must(template.ParseFiles("templates/views/index.html")) + //check for go partial templates so you can extract blocks you want to use indexTemplate.Execute(w, passarg) }