So my current project is using github.com/gorilla/mux for the handling, i also need to have a file server on it, it will just list all files in a directory and allow the browser to download or look at them. I am currently doing this bellow
router.PathPrefix("/files/").Handler(http.StripPrefix("/files/", http.FileServer(http.Dir("./Profiles/"))))
I need to protect this page so that not just anyone can see it and get the files... Whats the most simple way i can do this?
评论:
luckyleprechaun98:
tgulacsi:Yep basic auth is the way to go. You can use a middleware but you still need TLS to keep it secure. At that point it's easier to stick Caddy in front and use its basic auth directive. It will set up TLS for you automatically.
See http://elithrar.github.io/article/httpauth-basic-auth-for-go/
