你的问题有点误导,因为它问的是如何在Web浏览器中打开本地页面,但实际上您想知道如何启动Web服务器以便可以在浏览器中打开它.

http.FileServer()
/tmp/data
http.Handle("/", http.FileServer(http.Dir("/tmp/data")))
panic(http.ListenAndServe(":8080", nil))
net/http
func myHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello from Go")
}

func main() {
    http.HandleFunc("/", myHandler)
    panic(http.ListenAndServe(":8080", nil))
}
github.com/icza/goxosx.OpenDefault()
// open opens the specified URL in the default browser of the user.
func open(url string) error {
    var cmd string
    var args []string

    switch runtime.GOOS {
    case "windows":
        cmd = "cmd"
        args = []string{"/c", "start"}
    case "darwin":
        cmd = "open"
    default: // "linux", "freebsd", "openbsd", "netbsd"
        cmd = "xdg-open"
    }
    args = append(args, url)
    return exec.Command(cmd, args...).Start()
}

此示例代码取自Gowut(Go WebUI Toolkit;披露:我是作者).

exec.Command()&&"^&"strings.ReplaceAll(url, "&", "^&")

使用此命令在默认浏览器中打开以前启动的Web服务器:

open("http://localhost:8080/")
http.ListenAndServe()
go open("http://localhost:8080/")
panic(http.ListenAndServe(":8080", nil))

查看此问题,了解其他可选方法:在Web服务器启动后如何启动浏览器:Go: How can I start the browser AFTER the server started listening?