forked from krimler/go-ftw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (55 loc) · 1.38 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
// 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 (
"fmt"
"os"
"time"
_ "time/tzdata"
"github.com/fzipi/go-ftw/cmd"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
// nolint: gochecknoglobals
var (
version = "dev"
commit = ""
date = ""
builtBy = ""
)
func main() {
const file_name string = "ftw.log"
file, err := os.Create(file_name)
if err != nil {
fmt.Println("Critical: Invalid Log filei: ", file_name)
}
defer file.Close()
log.Logger = log.Output(file)
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
// Load timezone location based on TZ
tzone, _ := time.Now().Zone()
loc, err := time.LoadLocation(tzone)
if err != nil {
log.Info().Msgf("ftw/main: cannot load timezone")
} else {
time.Local = loc // -> set the global timezone
}
cmd.Execute(
buildVersion(version, commit, date, builtBy),
)
}
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
}