File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package url
33import (
44 "fmt"
55 "net/url"
6+ "os/exec"
7+ "runtime"
68 "strings"
79
810 "github.com/gruntwork-io/go-commons/errors"
@@ -52,3 +54,24 @@ func mergeQuery(originalQuery url.Values, newQuery url.Values) url.Values {
5254func stripSlashes (str string ) string {
5355 return strings .Trim (str , "/" )
5456}
57+
58+ // Attempt to open a URL in the user's browser. We use this to open docs, PRs we've
59+ // programmatically opened, etc
60+ func OpenURL (url string ) error {
61+ var err error
62+
63+ switch runtime .GOOS {
64+ case "linux" :
65+ err = exec .Command ("xdg-open" , url ).Start ()
66+ case "windows" :
67+ err = exec .Command ("rundll32" , "url.dll,FileProtocolHandler" , url ).Start ()
68+ case "darwin" :
69+ err = exec .Command ("open" , url ).Start ()
70+ default :
71+ err = fmt .Errorf ("unsupported platform" )
72+ }
73+ if err != nil {
74+ return err
75+ }
76+ return nil
77+ }
You can’t perform that action at this time.
0 commit comments