package main
import (
"fmt"
"net/http"
"os/exec"
"runtime"
)
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()
}
func main() {
fs := http.FileServer(http.Dir("wwwroot/"))
http.Handle("/", http.StripPrefix("/", fs))
fmt.Println("服务地址:http://127.0.0.1:8080")
open("http://127.0.0.1:8080");
if err := http.ListenAndServe(":8080", nil); err != nil {
fmt.Println("服务无法启动,8080端口被占用")
}
}