1、本地文件目录如下:
2、macaron配置
package main
import (
"log"
"net/http"
"gopkg.in/macaron.v1"
)
func myHandler(ctx *macaron.Context) string {
return "the request path is: " + ctx.Req.RequestURI
}
func main() {
m := macaron.Classic()
m.Use(macaron.Static("/test/images", macaron.StaticOptions{
Prefix:"images",
}))
m.Get("/test", myHandler)
log.Println("Server is running...")
log.Println(http.ListenAndServe("0.0.0.0:4000", m))
}
m.Use(macaron.Static("/test/images", macaron.StaticOptions{
Prefix:"images",
}))
/test/images :本地目录
images : uri前缀
3、静态资源访问路径:
http://127.0.0.1:4000/images/2/hello.text
效果如下: