Protect a FileServer?

xuanbao · 2016-10-30 08:00:11 · 650 次点击    
这是一个分享于 2016-10-30 08:00:11 的资源,其中的信息可能已经有所发展或是发生改变。

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:

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.

tgulacsi:

See http://elithrar.github.io/article/httpauth-basic-auth-for-go/


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

650 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传