Last active
February 2, 2026 19:00
-
-
Save sevkin/9798d67b2cb9d07cb05f89f14ba682f8 to your computer and use it in GitHub Desktop.
golang open url in default browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only way I could get this to work on my Windows 10 machine, helpful link from @Xxproner. Quotes being wrapped around
urlseem to be getting stripped byexec?