-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration.go
More file actions
52 lines (43 loc) · 887 Bytes
/
configuration.go
File metadata and controls
52 lines (43 loc) · 887 Bytes
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
package main
import (
"log"
"os"
"os/user"
"github.com/BurntSushi/toml"
)
// Info from config file
type Config struct {
Email string
}
// getDotFilePath returns the dot file for the repos list.
// Creates it and the enclosing folder if it does not exist.
func getDotFilePath() string {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
dotFile := usr.HomeDir + "/.gitstats"
_, err = os.Stat(dotFile)
if err == nil {
return dotFile
}
f, err := os.Create(dotFile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
return dotFile
}
// Reads info from config file
func ReadConfig() Config {
var configfile = getDotFilePath()
_, err := os.Stat(configfile)
if err != nil {
log.Fatal("Config file is missing: ", configfile)
}
var config Config
if _, err := toml.DecodeFile(configfile, &config); err != nil {
log.Fatal(err)
}
return config
}