+++
Assets and Files
This example will show how to serve static files like CSSs, JavaScripts or images from a specific directory.
// 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;
}
当前内容版权归 gowebexamples 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 gowebexamples .