-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (56 loc) · 1.56 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
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl 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/srv6-ctrl/internal/app"
"github.com/nextmn/srv6-ctrl/internal/config"
"github.com/nextmn/srv6-ctrl/internal/logger"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func main() {
logger.Init("Nextm-SRv6-ctrl")
var config_file string
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
app := &cli.App{
Name: "NextMN-SRv6-ctrl",
Usage: "Controller for NextMN-SRv6",
EnableBashCompletion: true,
Authors: []*cli.Author{
{Name: "Louis Royer"},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Load configuration from `FILE`",
Destination: &config_file,
Required: true,
DefaultText: "not set",
},
},
Action: func(c *cli.Context) error {
conf, err := config.ParseConf(config_file)
if err != nil {
logrus.WithContext(ctx).WithError(err).Fatal("Error loading config, exiting…")
}
if conf.Logger != nil {
logrus.SetLevel(conf.Logger.Level)
}
if err := app.NewSetup(conf).Run(ctx); err != nil {
logrus.WithError(err).Fatal("Error while running, exiting…")
}
return nil
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}