forked from gitter-badger/khabar
/
main.go
68 lines (53 loc) · 1.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
// Package main is the CLI.
// You can use the CLI via Terminal.
package main
import (
"log"
"os"
"path/filepath"
"github.com/bulletind/khabar/config"
"github.com/bulletind/khabar/db"
"github.com/nicksnyder/go-i18n/i18n"
"gopkg.in/simversity/gottp.v3"
)
func sysInit() {
<-(gottp.SysInitChan) //Buffered Channel to receive the server upstart boolean
config.InitTracer()
log.Println("Initialized GoTracer")
db.Conn = db.GetConn(
config.Settings.Khabar.DBName,
config.Settings.Khabar.DBAddress,
config.Settings.Khabar.DBUsername,
config.Settings.Khabar.DBPassword,
)
log.Println("Database Connected :" + config.Settings.Khabar.DBName + " " +
"at address:" + config.Settings.Khabar.DBAddress)
transDir := config.Settings.Khabar.TranslationDirectory
if len(transDir) == 0 {
cwd := os.Getenv("PWD")
transDir = cwd + "/translations"
config.Settings.Khabar.TranslationDirectory = cwd
}
log.Println("Directory for translation :" + transDir)
filepath.Walk(transDir, func(path string, _ os.FileInfo, err error) error {
fileExt := filepath.Ext(path)
if fileExt == ".json" && err == nil {
log.Println("Loading translation file:" + path)
i18n.MustLoadTranslationFile(path)
} else {
log.Print("Skipping translation file:" + path + " " +
"File Extension:" + fileExt + " ")
if err != nil {
log.Print("Error:" + err.Error())
}
}
return nil
})
log.SetFlags(log.Ldate | log.Ltime | log.Llongfile)
log.Println("Translations have been parsed.")
}
func main() {
go sysInit()
registerHandlers()
gottp.MakeServer(&config.Settings)
}