Assets and Files
这个例子将展示如何使用静态文件比如CSS、 JavaScripts或图片.
// static-files.go
package main
import "net/http"
func main() {
fs := http.FileServer(http.Dir("assets/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.ListenAndServe(":8080", nil)
}
$ tree assets/
assets/
└── css
└── styles.css
$ go run static-files.go
$ curl -s http://localhost:8080/static/css/styles.css
body {
background-color: black;
}
当前内容版权归 go-chinese-site 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 go-chinese-site .