var commands = map[string]string{
"windows": "cmd",
"darwin": "open",
"linux": "xdg-open",
}
// Open calls the OS default program for uri
func Open(uri string) error {
run, ok := commands[runtime.GOOS]
if runtime.GOOS=="windows" {
uri = "/c start "+ uri
}
if !ok {
return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
}
cmd := exec.Command(run, uri)
return cmd.Start()
}
reference:https://studygolang.com/topics/4904