Golang 简单静态web服务器
直接使用 net.http 包,非常方便
// staticWeb
package main
import (
"fmt"
"net/http"
"strconv"
)
//传入url参数、静态文件存放目录、监听的端口号
func StaticRunServer(urlPath string, filePath string, port int) {
http.Handle(urlPath, http.FileServer(http.Dir(filePath)))
fmt.Print("Run server!")
portStr := strconv.Itoa(port)
http.ListenAndServe(":"+portStr, nil)
}