-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
64 lines (52 loc) · 1.25 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
// Copyright 2024 OWASP CRS Project
// SPDX-License-Identifier: Apache-2.0
// Package go-ftw is a Framework for Testing Web Application Firewalls
// It is derived from the work made with the pytest plugin `ftw`
package main
import (
"context"
"errors"
"fmt"
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
_ "time/tzdata"
"github.com/coreruleset/go-ftw/cmd"
)
const (
ExecutableName = "go-ftw"
)
// nolint: gochecknoglobals
var (
version = "dev"
commit = ""
date = ""
builtBy = ""
)
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
err := cmd.Execute(
buildVersion(version, commit, date, builtBy),
)
if errors.Is(err, context.DeadlineExceeded) {
os.Exit(2)
} else if err != nil {
os.Exit(1)
}
}
func buildVersion(version, commit, date, builtBy string) string {
var result = version
if commit != "" {
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
}
if date != "" {
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
}
if builtBy != "" {
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
}
return result
}