Skip to content

Instantly share code, notes, and snippets.

@hhstore
Created April 18, 2019 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhstore/4864ee7c2dde11a1b883486589ec7359 to your computer and use it in GitHub Desktop.
Save hhstore/4864ee7c2dde11a1b883486589ec7359 to your computer and use it in GitHub Desktop.
go 静态资源 web 服务器
package main
import (
"log"
"net/http"
)
// 静态资源 web 服务器:
// - 适用纯静态资源的 docs 服务
// - 普通文件服务器: mp3/txt 等
func main() {
// 静态资源路径:
docsPath := "./docs"
// URL前缀:
urlPrefix := "/x/docs/"
http.Handle(urlPrefix, http.StripPrefix(urlPrefix, http.FileServer(http.Dir(docsPath))))
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment