-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathmain.go
64 lines (54 loc) · 1.42 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
// mtg is just a command-line application that starts a proxy.
//
// Application logic is how to read a config and configure mtglib.Proxy.
// So, probably you need to read the documentation for mtglib package
// first.
//
// mtglib is a core of the application. The rest of the packages provide
// some default implementations for the interfaces, defined in mtglib.
package main
import (
"fmt"
"math/rand"
"runtime/debug"
"strconv"
"time"
"github.com/9seconds/mtg/v2/internal/cli"
"github.com/9seconds/mtg/v2/internal/utils"
"github.com/alecthomas/kong"
)
var version = "dev" // has to be set by ldflags
func main() {
rand.Seed(time.Now().UTC().UnixNano())
if err := utils.SetLimits(); err != nil {
panic(err)
}
if buildInfo, ok := debug.ReadBuildInfo(); ok {
vcsCommit := "<no-commit>"
vcsDate := time.Now()
vcsDirty := ""
for _, setting := range buildInfo.Settings {
switch setting.Key {
case "vcs.time":
vcsDate, _ = time.Parse(time.RFC3339, setting.Value)
case "vcs.revision":
vcsCommit = setting.Value
case "vcs.modified":
if isDirty, _ := strconv.ParseBool(setting.Value); isDirty {
vcsDirty = " [dirty]"
}
}
}
version = fmt.Sprintf("%s (%s: %s on %s%s)",
version,
buildInfo.GoVersion,
vcsDate.Format(time.RFC3339),
vcsCommit,
vcsDirty)
}
cli := &cli.CLI{}
ctx := kong.Parse(cli, kong.Vars{
"version": version,
})
ctx.FatalIfErrorf(ctx.Run(cli, version))
}