admin: introducing new page

This commit is contained in:
nemunaire 2018-02-16 11:42:41 +01:00
commit 185262b2e7
3 changed files with 49 additions and 0 deletions

View file

@ -91,6 +91,15 @@ func main() {
GetNextImage,
)))
mux.HandleFunc("/admin/", func(w http.ResponseWriter, r *http.Request) {
if authFunc(r) == nil {
w.Header().Set("WWW-Authenticate", "Basic realm=\"YouP0m Admin\"")
http.Error(w, "You are not allowed to perform this request.", http.StatusUnauthorized)
} else {
http.ServeFile(w, r, filepath.Join(staticDir, "admin.html"))
}
})
log.Println("Ready, listening on", *bind)
if err := http.ListenAndServe(*bind, mux); err != nil {
log.Fatal("Unable to listen and serve: ", err)