-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
48 lines (43 loc) · 967 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
)
func (sol *solution) parseConfig() error {
// parse config file
if _, err := os.Stat(configJSONPath); os.IsNotExist(err) {
return errors.New("failed to find config file")
}
jsonBytes, err := ioutil.ReadFile(configJSONPath)
if err != nil {
return err
}
return json.Unmarshal(jsonBytes, &sol.Config)
}
type errorFunc func() error
func checkErrors(errChecks ...errorFunc) error {
for _, errFunc := range errChecks {
err := errFunc()
if err != nil {
return err
}
}
return nil
}
func openBrowserURL(urlAddress string) error {
switch runtime.GOOS {
case "linux":
return exec.Command("xdg-open", urlAddress).Start()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", urlAddress).Start()
case "darwin":
return exec.Command("open", urlAddress).Start()
default:
return fmt.Errorf("unsupported platform")
}
}