Add querylog

This commit is contained in:
Your Name 2018-09-02 21:48:12 +00:00
parent 9a612a6281
commit 42ddb1b77d
1 changed files with 3 additions and 1 deletions

View File

@ -29,6 +29,8 @@ func init() {
func main() { func main() {
r := mux.NewRouter() r := mux.NewRouter()
r.Use(BasicAuth) r.Use(BasicAuth)
r.Use(QueryLog)
r.PathPrefix("/").Handler(http.StripPrefix("/", enhancedfileserver.FileServer(http.Dir("./")))) r.PathPrefix("/").Handler(http.StripPrefix("/", enhancedfileserver.FileServer(http.Dir("./"))))
a := fmt.Sprintf("%s:%d", c.Listen, c.Port) a := fmt.Sprintf("%s:%d", c.Listen, c.Port)
@ -41,7 +43,7 @@ func BasicAuth(next http.Handler) http.Handler {
if c.Username != "" && c.Password != "" { if c.Username != "" && c.Password != "" {
user, pass, ok := r.BasicAuth() user, pass, ok := r.BasicAuth()
if !ok || user != c.Username || pass != c.Password { if !ok || user != c.Username || pass != c.Password {
w.Header().Set("WWW-Authenticate", `Basic realm="mydomain"`) w.Header().Set("WWW-Authenticate", `Basic realm="mydomains"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized) http.Error(w, "Unauthorized", http.StatusUnauthorized)
} }