-
Notifications
You must be signed in to change notification settings - Fork 4
/
golerta.go
61 lines (49 loc) · 1.35 KB
/
golerta.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
package main
import (
"fmt"
"log"
"github.com/allen13/golerta/app"
"github.com/allen13/golerta/app/auth/token"
"github.com/allen13/golerta/app/config"
"github.com/docopt/docopt-go"
)
const version = "Golerta 0.1.0"
const usage = `Golerta.
Usage:
golerta server [--config=<config>]
golerta createAgentToken <name> [--config=<config>]
golerta --help
golerta --version
Options:
--config=<config> The golerta config [default: ./golerta.toml].
--help Show this screen.
--version Show version.
`
func main() {
args, err := docopt.Parse(usage, nil, true, version, false)
if err != nil {
log.Fatalln(err)
}
configFile := args["--config"].(string)
config := config.BuildConfig(configFile)
if args["server"].(bool) {
echo := app.BuildApp(config)
log.Println("Starting golerta server...")
var err error
if config.Golerta.TLSEnabled {
if config.Golerta.TLSAutoEnabled {
err = echo.StartAutoTLS(config.Golerta.BindAddr)
} else {
err = echo.StartTLS(config.Golerta.BindAddr, config.Golerta.TLSCert, config.Golerta.TLSKey)
}
} else {
err = echo.Start(config.Golerta.BindAddr)
}
if err != nil {
echo.Logger.Fatal(err)
}
}
if args["createAgentToken"].(bool) {
fmt.Println(token.CreateExpirationFreeAgentToken(args["<name>"].(string), config.Golerta.SigningKey))
}
}