Skip to content

Instantly share code, notes, and snippets.

@nanmu42
Created May 20, 2019 09:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nanmu42/4fbaf26c771da58095fa7a9f14f23d27 to your computer and use it in GitHub Desktop.
Save nanmu42/4fbaf26c771da58095fa7a9f14f23d27 to your computer and use it in GitHub Desktop.
Golang: Open URL in Browser
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)
}
}
@tharinduwijewardane
Copy link

Is there a way to pass an authentication header? Like the -H option in curl

@nanmu42
Copy link
Author

nanmu42 commented Oct 8, 2019

As far as I know, no.

Maybe use a token in query string?

@tharinduwijewardane
Copy link

Yes I will have to do a workaround. Thanks.

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