Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@tharinduwijewardane tharinduwijewardane commented Oct 8, 2019

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

@nanmu42

This comment has been minimized.

Copy link
Owner Author

@nanmu42 nanmu42 commented Oct 8, 2019

As far as I know, no.

Maybe use a token in query string?

@tharinduwijewardane

This comment has been minimized.

Copy link

@tharinduwijewardane tharinduwijewardane commented Oct 9, 2019

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