This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
claw.go
66 lines (54 loc) · 1.41 KB
/
claw.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 main
import "os"
import "os/signal"
import "os/user"
import "path/filepath"
import "runtime"
import "flag"
import "github.com/cnf/go-claw/dispatcher"
import "github.com/cnf/go-claw/clog"
var cfgfile string
var verbose bool
func main() {
defer clog.Stop()
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt)
go func() {
<- sigc
clog.Stop()
os.Exit(1)
}()
setup()
clog.SetFlags(clog.Lshortlevel | clog.Ltimebetween | clog.Ltime)
if verbose {
clog.SetLogLevel(clog.DEBUG)
} else {
clog.SetLogLevel(clog.WARN)
}
registerAllListeners()
registerAllTargets()
dispatch := dispatcher.Dispatcher{}
dispatch.Configfile = cfgfile
dispatch.Start()
}
func setup() {
var home string
usr, uerr := user.Current()
if uerr != nil {
clog.Warn( uerr.Error() )
home = os.ExpandEnv("$HOME")
} else {
home = usr.HomeDir
}
if runtime.GOOS == "windows" {
// cfg.Home, _ = filepath.Abs(usr.HomeDir)
// TODO: Different defaults for windows
} else {
// cfg.Home, _ = filepath.Abs(usr.HomeDir)
cfgfile = filepath.Join(home, ".config/claw/config.json")
}
flag.StringVar(&cfgfile, "conf", cfgfile, "path to our config file.")
flag.BoolVar(&verbose, "v", verbose, "turn on verbose logging")
flag.Parse()
cfgfile, _ = filepath.Abs(cfgfile)
}