-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
60 lines (48 loc) · 1.46 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
/*
Copyright ArxanChain Ltd. 2020 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"fmt"
"os"
"github.com/csiabb/donation-service/common/log"
"github.com/csiabb/donation-service/common/metadata"
"github.com/csiabb/donation-service/config"
"github.com/csiabb/donation-service/service"
"gopkg.in/alecthomas/kingpin.v2"
)
//command line flags
var (
programName = "donation-service"
logger = log.MustGetLogger("main")
app = kingpin.New(metadata.ProgramName, "rest server for client business integration")
startCmd = app.Command("start", fmt.Sprintf("Start the %s server", metadata.ProgramName)).Default()
versionCmd = app.Command("version", "Show version information")
)
func cleanup() {
}
func main() {
defer cleanup()
kingpin.Version("0.0.1")
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
// "start" command
case startCmd.FullCommand():
// parse configure
conf := config.GetServiceCfg(metadata.ProgramName)
// init log
log.InitLogConfig(&conf.Log)
logger.Infof("Starting %s", metadata.ProgramVersion.FullVersion())
logger.Debugf("initialize configure %+v", conf)
server, err := service.NewServer(conf, metadata.ProgramVersion)
if err != nil {
logger.Panicf("Failed to create %s server, %+v", metadata.ProgramName, err)
return
}
logger.Infof("Beginning to serve requests")
server.Start()
// "version" command
case versionCmd.FullCommand():
fmt.Println(metadata.ProgramVersion.FullVersion())
}
}