Skip to content

Instantly share code, notes, and snippets.

@sevkin
Last active June 11, 2024 03:10
Show Gist options
  • Save sevkin/9798d67b2cb9d07cb05f89f14ba682f8 to your computer and use it in GitHub Desktop.
Save sevkin/9798d67b2cb9d07cb05f89f14ba682f8 to your computer and use it in GitHub Desktop.
golang open url in default browser
// https://stackoverflow.com/questions/39320371/how-start-web-server-to-open-page-in-browser-in-golang
// 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()
}
@obutora
Copy link

obutora commented Jun 11, 2024

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment