ZH_Static

Lunny Xiao edited this page Jan 13, 2015 · 2 revisions

Static 让你用一行代码可以完成一个静态服务器。

func main() {
    t := tango.New(tango.Static())
    t.Run()
}

然后,将你的文件放到 ./public 目录下,你就可以通过浏览器放问到他们。比如:

http://localhost/images/logo.png  --> ./public/images/logo.png

当然,你也可以加入你basicauth或者你自己的认证中间件,这样就变为了一个私有的文件服务器。

func main() {
    t := tango.New()
    t.Use(AuthHandler)
    t.Use(tango.Static())
    t.Run()
}

你也可以通过StaticOptions来改变Static的默认参数,比如:

t.Use(tango.Static(tango.StaticOptions{Prefix:"static"}))
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.