/
main.go
72 lines (61 loc) · 1.47 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
69
70
71
72
package main
import (
"log"
"os"
"strconv"
"github.com/codegangsta/cli"
"github.com/wadahiro/issue-note/server/repos"
"github.com/wadahiro/issue-note/server/services"
)
var CommitHash = "WORKSPACE" // inject by LDFLAGS build option
var Version = "SNAPSHOT" // inject by LDFLAGS build option
var BuildTarget = "develop" // inject by LDFLAGS build option
const DATA_DIR = "./data"
func main() {
if BuildTarget == "develop" {
RunServer(nil)
} else {
app := cli.NewApp()
app.Name = "ISSUE-NOTE"
app.Version = Version
app.Usage = ""
app.Author = "Hiroyuki Wada"
app.Email = "wadahiro@gmail.com"
app.Commands = []cli.Command{
{
Name: "run",
Usage: "Runs issue-note server",
Action: RunServer,
},
}
app.Flags = []cli.Flag{
cli.IntFlag{
Name: "port",
Value: 3000,
Usage: "port number",
},
}
app.Run(os.Args)
}
}
func RunServer(c *cli.Context) {
log.Println("-------------- ISSUE-NOTE --------------")
log.Println("VERSION: ", Version)
log.Println("COMMIT_HASH: ", CommitHash)
log.Println("----------------------------------------")
if err := os.MkdirAll(DATA_DIR, 0644); err != nil {
log.Fatalln(err)
}
repo := repo.InitSQLite(DATA_DIR)
service.RunSyncScheduler(repo)
debugMode := false
if BuildTarget == "develop" {
debugMode = true
}
port := "3000"
if c != nil && c.GlobalInt("port") != 0 {
port = strconv.Itoa(c.GlobalInt("port"))
}
initRouter(repo, port, debugMode)
log.Println("Started ISSUE-NOTE")
}