-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (87 loc) · 2.57 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
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/nextmn/json-api/healthcheck"
"github.com/nextmn/logrus-formatter/logger"
"github.com/nextmn/ue-lite/internal/app"
"github.com/nextmn/ue-lite/internal/config"
"github.com/adrg/xdg"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func main() {
logger.Init("NextMN-UE Lite")
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
app := &cli.App{
Name: "NextMN-UE Lite",
Usage: "Experimental UE Simulator",
EnableBashCompletion: true,
Authors: []*cli.Author{
{Name: "Louis Royer"},
},
Flags: []cli.Flag{
&cli.PathFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Load configuration from `FILE`",
Required: false,
DefaultText: "${XDG_CONFIG_DIRS}/nextmn-ue-lite/config.yaml",
EnvVars: []string{"CONFIG_FILE"},
},
},
Before: func(ctx *cli.Context) error {
if ctx.Path("config") == "" {
if xdgPath, err := xdg.SearchConfigFile("nextmn-ue-lite/config.yaml"); err != nil {
cli.ShowAppHelp(ctx)
logrus.WithError(err).Fatal("No configuration file defined")
} else {
ctx.Set("config", xdgPath)
}
}
return nil
},
Action: func(ctx *cli.Context) error {
conf, err := config.ParseConf(ctx.Path("config"))
if err != nil {
logrus.WithContext(ctx.Context).WithError(err).Fatal("Error loading config, exiting…")
}
if conf.Logger != nil {
logrus.SetLevel(conf.Logger.Level)
}
if err := app.NewSetup(conf).Run(ctx.Context); err != nil {
logrus.WithError(err).Fatal("Error while running, exiting…")
}
return nil
},
Commands: []*cli.Command{
{
Name: "healthcheck",
Usage: "check status of the node",
Action: func(ctx *cli.Context) error {
conf, err := config.ParseConf(ctx.Path("config"))
if err != nil {
logrus.WithContext(ctx.Context).WithError(err).Fatal("Error loading config, exiting…")
}
if conf.Logger != nil {
logrus.SetLevel(conf.Logger.Level)
}
if err := healthcheck.NewHealthcheck(*conf.Control.Uri.JoinPath("status"), "go-github-nextmn-ue-lite").Run(ctx.Context); err != nil {
os.Exit(1)
}
return nil
},
},
},
}
if err := app.RunContext(ctx, os.Args); err != nil {
logrus.Fatal(err)
}
}