-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (64 loc) · 1.86 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
// Copyright 2022 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/logrus-formatter/logger"
"github.com/nextmn/upf/internal/app"
"github.com/nextmn/upf/internal/config"
"github.com/adrg/xdg"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func main() {
logger.Init("NextMN-UPF")
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
app := &cli.App{
Name: "NextMN-UPF",
Usage: "Experimental 5G UPF",
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-upf/config.yaml",
EnvVars: []string{"CONFIG_FILE"},
},
},
Action: func(ctx *cli.Context) error {
if ctx.Path("config") == "" {
if xdgPath, err := xdg.SearchConfigFile("nextmn-upf/config.yaml"); err != nil {
cli.ShowAppHelp(ctx)
logrus.WithError(err).Fatal("No configuration file defined")
} else {
ctx.Set("config", xdgPath)
}
}
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
},
}
if err := app.RunContext(ctx, os.Args); err != nil {
logrus.Fatal(err)
}
}