-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
55 lines (46 loc) · 999 Bytes
/
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
package main
import (
"errors"
"log"
"os"
"github.com/flashbots/go-template/common"
"github.com/urfave/cli/v2" // imports as package "cli"
)
var flags []cli.Flag = []cli.Flag{
&cli.BoolFlag{
Name: "log-json",
Value: false,
Usage: "log in JSON format",
},
&cli.BoolFlag{
Name: "log-debug",
Value: false,
Usage: "log debug messages",
},
}
func main() {
app := &cli.App{
Name: "httpserver",
Usage: "Serve API, and metrics",
Flags: flags,
Action: runCli,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func runCli(cCtx *cli.Context) error {
logJSON := cCtx.Bool("log-json")
logDebug := cCtx.Bool("log-debug")
log := common.SetupLogger(&common.LoggingOpts{
Debug: logDebug,
JSON: logJSON,
Version: common.Version,
})
log.Info("Starting the project")
log.Debug("debug message")
log.Info("info message")
log.With("key", "value").Warn("warn message")
log.Error("error message", "err", errors.ErrUnsupported)
return nil
}