fix password but no username, update modules
This commit is contained in:
parent
0fd317fd56
commit
c9a0ba672e
2
go.mod
2
go.mod
|
@ -3,6 +3,6 @@ module git.teamworkapps.com/shortcut/httphere
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7
|
||||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756
|
||||
github.com/gorilla/mux v1.8.0
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,4 +1,6 @@
|
|||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7 h1:wl0faTtewN9Y0nTZpRY2mcaIhVkaR1l8k920U0rDIk0=
|
||||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20181107163431-49cae39a0eb7/go.mod h1:4t5y+BFcMRTe6GkAX72YXcjrKbGkOVM7CkJMRHNZYiQ=
|
||||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756 h1:ViHTT1GI1JlsLrUsivl4tvg6DySn35d1C3bzXeLa8uY=
|
||||
git.teamworkapps.com/shortcut/enhancedfileserver v0.0.0-20230421162957-948ff8787756/go.mod h1:Px7gD0CL+z9WBsvFPtCuDpVEJNStJXrbFRD3q7aJwYk=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
|
|
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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue