From 277d6c5b484f4fd485eb1e9808091e702287503b Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Sun, 6 Oct 2019 02:41:34 +0200 Subject: [PATCH] Add index --- handlers/index.go | 32 ++++++++++++++++++++++++++++++++ server/server.go | 4 +--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 handlers/index.go diff --git a/handlers/index.go b/handlers/index.go new file mode 100644 index 0000000..76e85d5 --- /dev/null +++ b/handlers/index.go @@ -0,0 +1,32 @@ +package handlers + +import ( + "net/http" +) + +// Index handler. +type Index struct { +} + +// NewIndex returns new Index handler. +func NewIndex() *Index { + return &Index{} +} + +// ServeHTTP handles requests on incoming connections. +func (i *Index) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" && r.Method != "HEAD" { + http.Error(w, "405 Method Not Allowed", http.StatusMethodNotAllowed) + return + } + + w.Write([]byte(` + cam2ip + +

cam2ip

+

html

+

jpeg

+

mjpeg

+ + `)) +} diff --git a/server/server.go b/server/server.go index eccd140..7681ebb 100644 --- a/server/server.go +++ b/server/server.go @@ -58,9 +58,7 @@ func (s *Server) ListenAndServe() error { w.WriteHeader(http.StatusOK) }) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - }) + http.Handle("/", newAuthHandler(handlers.NewIndex(), basic)) srv := &http.Server{}