-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (46 loc) · 1.24 KB
/
main.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
package main
import (
"flag"
"os"
"github.com/ctaoist/gammu-web/config"
"github.com/ctaoist/gammu-web/db"
"github.com/ctaoist/gammu-web/smsd"
"github.com/ctaoist/gammu-web/web"
log "github.com/sirupsen/logrus"
)
func init() {
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
ForceColors: false,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
log.SetLevel(log.InfoLevel)
}
func main() {
debug := flag.Bool("debug", false, "Debug mode")
port := flag.String("port", "21234", "Server listen port")
flag.BoolVar(&config.TestMode, "test", false, "Test mode, and not start gammu service")
flag.StringVar(&config.AccessToken, "token", "", "Api access token")
gammurc := flag.String("gammu-conf", "~/.gammurc", "Gammu config file")
flag.StringVar(&config.LogFile, "log", "", "Log to file, default to stdout")
flag.Parse()
if *debug {
log.SetLevel(log.DebugLevel)
}
if config.LogFile != "" {
f, err := os.OpenFile(config.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatal("LogInit", err)
}
defer f.Close()
log.SetOutput(f)
}
log.Info("Init", "Initializing...")
db.Init()
if !config.TestMode {
smsd.Init(*gammurc)
defer smsd.Close()
}
web.RunServer(*port)
}