Created
April 18, 2019 02:13
-
-
Save hhstore/4864ee7c2dde11a1b883486589ec7359 to your computer and use it in GitHub Desktop.
go 静态资源 web 服务器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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