Skip to content

Instantly share code, notes, and snippets.

@zazk
Forked from hyg/gist:9c4afcd91fe24316cbf0
Last active November 21, 2017 17:05
Show Gist options
  • Select an option

  • Save zazk/8c7a436e79063fa39e3c180b773d932b to your computer and use it in GitHub Desktop.

Select an option

Save zazk/8c7a436e79063fa39e3c180b773d932b to your computer and use it in GitHub Desktop.
open browser in golang
import(
"runtime"
"log"
)
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment