Protect a FileServer?

xuanbao · · 520 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>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</p> <p>router.PathPrefix(&#34;/files/&#34;).Handler(http.StripPrefix(&#34;/files/&#34;, http.FileServer(http.Dir(&#34;./Profiles/&#34;))))</p> <p>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?</p> <hr/>**评论:**<br/><br/>luckyleprechaun98: <pre><p>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&#39;s easier to stick <a href="https://caddyserver.com" rel="nofollow">Caddy</a> in front and use its basic auth directive. It will set up TLS for you automatically. </p></pre>tgulacsi: <pre><p>See <a href="http://elithrar.github.io/article/httpauth-basic-auth-for-go/" rel="nofollow">http://elithrar.github.io/article/httpauth-basic-auth-for-go/</a> </p></pre>

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

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