-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
107 lines (87 loc) · 2.35 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
98
99
100
101
102
103
104
105
106
107
// Package main is the entry point for the contracts-api application.
package main
import (
"os"
"strconv"
"strings"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/CTO2BPublic/passage-server/pkg/api"
"github.com/CTO2BPublic/passage-server/pkg/config"
"github.com/CTO2BPublic/passage-server/pkg/crondriver"
"github.com/urfave/cli/v2"
)
// @version 0.1.0
// @title passage-server
// @description powerful, open-source access control management solution built in Go
// @contact.name API Support
// @contact.url https://cto2b.eu
// @contact.email tomas@cto2b.eu
// @license.name Apache 2.0
// @securityDefinitions.apikey JWT
// @in header
// @name Authorization
func main() {
config.InitConfig()
Config := config.GetConfig()
if Config.Log.Pretty {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
if Config.Log.Level == "debug" {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
config.PrintConfig(Config)
}
if Config.Log.Level == "info" {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
if Config.Log.Caller {
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string {
parts := strings.SplitAfter(file, "passage-server")
return parts[1] + ":" + strconv.Itoa(line)
}
log.Logger = log.With().Caller().Logger()
}
app := &cli.App{
// CLI metadata
Name: "passage-server",
Usage: "powerful, open-source access control management solution built in Go",
Version: "0.1.0",
EnableBashCompletion: true,
// Default command if none is passed
Action: func(cCtx *cli.Context) error {
cron := crondriver.GetDriver()
cron.Start()
server := api.GetServer()
server.SetupEngineWithDefaults()
server.RunEngine()
return nil
},
Commands: []*cli.Command{
{
Name: "server",
Aliases: []string{"s"},
Usage: "Manages API server",
Subcommands: []*cli.Command{
// SERVER start s
{
Name: "start",
Usage: "Start API server",
Aliases: []string{"s"},
Action: func(c *cli.Context) error {
cron := crondriver.GetDriver()
cron.Start()
server := api.GetServer()
server.SetupEngineWithDefaults()
server.RunEngine()
return nil
},
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal().Msg(err.Error())
}
}