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
3
3
import (
4
4
"fmt"
5
5
"net/url"
6
+ "os/exec"
7
+ "runtime"
6
8
"strings"
7
9
8
10
"github.com/gruntwork-io/go-commons/errors"
@@ -52,3 +54,24 @@ func mergeQuery(originalQuery url.Values, newQuery url.Values) url.Values {
52
54
func stripSlashes (str string ) string {
53
55
return strings .Trim (str , "/" )
54
56
}
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