fix password but no username, update modules
This commit is contained in:
18
main.go
18
main.go
@@ -16,7 +16,7 @@ type config struct {
|
||||
username string
|
||||
password string
|
||||
noindex bool
|
||||
nocache bool
|
||||
nocache bool
|
||||
log bool
|
||||
}
|
||||
|
||||
@@ -35,18 +35,22 @@ func init() {
|
||||
|
||||
func main() {
|
||||
r := mux.NewRouter()
|
||||
if c.username != "" && c.password == "" {
|
||||
if c.username == "" && c.password != "" {
|
||||
c.username = "admin"
|
||||
}
|
||||
if c.username != "" && c.password != "" {
|
||||
r.Use(basicAuth)
|
||||
}
|
||||
|
||||
if c.log {
|
||||
r.Use(queryLog)
|
||||
}
|
||||
|
||||
if c.username != "" && c.password != "" {
|
||||
r.Use(basicAuth)
|
||||
}
|
||||
|
||||
if c.nocache {
|
||||
r.Use(noCache)
|
||||
}
|
||||
|
||||
if c.noindex {
|
||||
r.PathPrefix("/").Handler(http.StripPrefix("/", enhancedfileserver.FileServerNoIndex(http.Dir("./"))))
|
||||
} else {
|
||||
@@ -60,8 +64,8 @@ func main() {
|
||||
|
||||
func noCache(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Cache-control", "no-cache, no-store")
|
||||
next.ServeHTTP(w,r)
|
||||
w.Header().Add("Cache-control", "no-cache, no-store")
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user