-
Notifications
You must be signed in to change notification settings - Fork 5
/
gossiped.go
80 lines (76 loc) · 1.61 KB
/
gossiped.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"github.com/askovpen/gossiped/pkg/areasconfig"
"github.com/askovpen/gossiped/pkg/config"
"github.com/askovpen/gossiped/pkg/ui"
"github.com/askovpen/gossiped/pkg/utils"
"log"
"os"
"path/filepath"
)
var (
version = "2.0"
commit = "dev"
)
func tryFindConfig() string {
for _, fn := range []string{
filepath.Join(os.Getenv("HOME"), "gossiped.yml"),
filepath.Join(os.Getenv("HOME"), ".config", "gossiped.yml"),
"/usr/local/etc/ftn/gossiped.yml",
"/etc/ftn/gossiped.yml",
"gossiped.yml",
} {
if utils.FileExists(fn) {
return fn
}
}
return ""
}
func main() {
if len(commit) > 8 {
commit = commit[0:8]
}
config.Version = version + "-" + commit
config.InitVars()
log.Printf("%s started", config.LongPID)
var fn string
if len(os.Args) == 1 {
fn = tryFindConfig()
if fn == "" {
log.Printf("Usage: %s <config.yml>", os.Args[0])
return
}
} else {
if utils.FileExists(os.Args[1]) {
fn = os.Args[1]
} else {
log.Printf("Usage: %s <config.yml>", os.Args[0])
return
}
}
log.Println(fmt.Sprintf("reading configuration from %s", fn))
err := config.Read(fn)
if err != nil {
log.Println(err)
return
}
f, _ := os.OpenFile(config.Config.Log, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
defer f.Close()
log.SetOutput(f)
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.Print("reading areas")
err = areasconfig.Read()
if err != nil {
log.Print(err)
return
}
// ui.App, err = gocui.NewGui(gocui.OutputNormal)
log.Print("starting ui")
app := ui.NewApp()
if err = app.Run(); err != nil {
log.Print("started ui")
log.Print(err)
return
}
}