File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 6
6
"fmt"
7
7
"io/ioutil"
8
8
"net/http"
9
+ "os/exec"
10
+ "runtime"
9
11
)
10
12
11
13
type DeviceCodeRequest struct {
@@ -66,6 +68,24 @@ func RequestDeviceCode() (string, error) {
66
68
67
69
fmt .Println ("open this url in your browser:" )
68
70
fmt .Println (response .VerificationUrlComplete )
71
+ err = openUrl (response .VerificationUrlComplete )
72
+ if err != nil {
73
+ return "" , fmt .Errorf ("failed to open url in browser: %v" , err )
74
+ }
69
75
70
76
return response .DeviceCode , nil
71
77
}
78
+
79
+ func openUrl (url string ) error {
80
+ var cmd * exec.Cmd
81
+ switch runtime .GOOS {
82
+ case "windows" :
83
+ cmd = exec .Command ("cmd" , "/c" , "start" , url )
84
+ case "darwin" :
85
+ cmd = exec .Command ("open" , url )
86
+ default :
87
+ cmd = exec .Command ("xdg-open" , url )
88
+ }
89
+
90
+ return cmd .Start ()
91
+ }
You can’t perform that action at this time.
0 commit comments