-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.23 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
package main
import (
"fmt"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
"github.com/weikunlu/go-api-template/cmd"
"github.com/weikunlu/go-api-template/cmd/database"
"github.com/weikunlu/go-api-template/config"
"os"
)
// Variables to identify the build
var (
Version string
Build string
BuildDate string
cliApp *cli.App
)
func init() {
// Initialise a CLI app
cliApp = cli.NewApp()
cliApp.Name = "App Phone Server"
cliApp.Usage = "appphone-service"
cliApp.Author = "Lucas Lu"
cliApp.Email = "lucas.lu@kkday.com"
cliApp.Version = fmt.Sprintf("%s-%s-%s", Version, Build, BuildDate)
}
func main() {
config.SetBuildConfig(Version, Build, BuildDate)
if os.Getenv("DEVELOP") == "true" {
cmd.RunServer()
return
}
// Set the CLI app commands
cliApp.Commands = []cli.Command{
{
Name: "runserver",
Usage: "run web server",
Action: func(c *cli.Context) error {
return cmd.RunServer()
},
},
{
Name: "migrate",
Usage: "run database migrate",
Action: func(c *cli.Context) error {
return database.RunMigration(c.Args().Get(0), c.Args().Get(1))
},
},
}
// Run the CLI app
if err := cliApp.Run(os.Args); err != nil {
fmt.Printf("startup error: %v", err.Error())
}
}