-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
49 lines (41 loc) · 797 Bytes
/
utils.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
49
package utils
import (
"net/url"
"os"
)
// Home returns the home directory of the current user withouth a trailing slash.
func Home() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
home += "/.portier"
if customHome := os.Getenv("PORTIER_HOME"); customHome != "" {
home = customHome
}
if _, err := os.Stat(home); err != nil {
if os.IsNotExist(err) {
perm := os.FileMode(0o700)
err := os.Mkdir(home, perm)
if err != nil {
return "", err
}
} else {
return "", err
}
}
return home, nil
}
type YAMLURL struct {
*url.URL
}
func (j *YAMLURL) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
err := unmarshal(&s)
if err != nil {
return err
}
url, err := url.Parse(s)
j.URL = url
return err
}