/
project.go
66 lines (54 loc) · 1.09 KB
/
project.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package project
import (
"os"
"path/filepath"
"strconv"
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
const (
hiddenFolderName = ".yaam"
Port = 25213
Host = "localhost"
Scheme = "http"
)
var (
PortString = strconv.Itoa(Port)
HostAndPort = Host + ":" + PortString
Url = Scheme + "://" + HostAndPort
)
func Config() error {
h, err := Home()
if err != nil {
return err
}
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(h)
if err := viper.ReadInConfig(); err != nil {
return err
}
log.Infof("config file used: '%s'", viper.ConfigFileUsed())
return nil
}
func Home() (string, error) {
h, err := homedir.Dir()
if err != nil {
return "", err
}
h = filepath.Join(h, hiddenFolderName)
if os.Getenv("YAAM_HOME") != "" {
h = os.Getenv("YAAM_HOME")
}
log.Tracef("yaam home: '%s'", h)
return h, nil
}
func RepositoriesHome() (string, error) {
h, err := Home()
if err != nil {
return "", err
}
h = filepath.Join(h, "repositories")
return h, nil
}