fix password but no username, update modules

This commit is contained in:
Your Name
2023-04-21 11:34:20 -05:00
parent 0fd317fd56
commit c9a0ba672e
3 changed files with 14 additions and 8 deletions

18
main.go
View File

@@ -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)
})
}