-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
97 lines (85 loc) · 1.76 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"os"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/wrfly/ecp"
"github.com/wrfly/yasuser/config"
"github.com/wrfly/yasuser/filter"
"github.com/wrfly/yasuser/routes"
"github.com/wrfly/yasuser/shortener"
)
var appName = "yasuser"
func main() {
app := &cli.App{
Name: appName,
Usage: "Yet another self-hosted URL shortener.",
Authors: author,
Version: fmt.Sprintf("Version: %s\tCommit: %s\tDate: %s",
Version, CommitID, BuildAt),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "config file path",
Aliases: []string{"c"},
Value: "./config.yml",
},
&cli.BoolFlag{
Name: "example",
Usage: "config file example",
Aliases: []string{"e"},
Value: false,
},
&cli.BoolFlag{
Name: "env-list",
Usage: "config environment lists",
Value: false,
},
},
Action: func(c *cli.Context) error {
conf := config.New()
if c.Bool("example") {
conf.Example()
return nil
}
if c.Bool("env-list") {
for _, e := range ecp.List(conf, appName) {
fmt.Println(e)
}
return nil
}
conf.Parse(c.String("config"))
if err := ecp.Parse(conf, appName); err != nil {
logrus.Error(err)
return err
}
if conf.Debug {
logrus.SetLevel(logrus.DebugLevel)
} else {
gin.SetMode(gin.ReleaseMode)
}
err := routes.Serve(
conf.Server,
shortener.New(conf.Store),
filter.New(conf.Filter),
)
if err != nil {
logrus.Error(err)
}
return nil
},
}
app.CustomAppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
AUTHOR:
{{range .Authors}}{{ . }}
{{end}}
VERSION:
{{.Version}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}`
app.Run(os.Args)
}