-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (50 loc) · 1.11 KB
/
main.go
File metadata and controls
63 lines (50 loc) · 1.11 KB
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
package main
import (
"time"
"strconv"
"os"
"go/build"
"github.com/PapiCZ/github-notifier/helpers"
"github.com/PapiCZ/github-notifier/settings"
"os/user"
)
func setHomeDir() {
usr, err := user.Current()
if err != nil {
panic(err)
}
settings.HomeDir = usr.HomeDir
}
func main() {
setHomeDir()
// Get GOPATH
goPath := os.Getenv("GOPATH")
if goPath == "" {
goPath = build.Default.GOPATH
}
if len(os.Args) > 1 {
cmd := helpers.NewCommand(settings.HomeDir, goPath, settings.SrcRoot)
switch os.Args[1] {
case "start":
cmd.Start(settings.PidFileName)
break
case "stop":
cmd.Stop(settings.PidFileName)
break
case "install":
cmd.Install()
break
}
} else {
runApp(settings.HomeDir, settings.ConfigFileName)
}
}
func runApp(homeDir string, configFileName string) {
config := helpers.NewConfig(homeDir + settings.ConfigPath + "/" + configFileName)
github := helpers.NewGithubNotifier(config.Get("api_token"))
interval, err := strconv.ParseInt(config.Get("interval"), 10, 0)
if err != nil {
panic(err)
}
github.ListenToNotifications(time.Duration(interval) * time.Second)
}