This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.go
73 lines (65 loc) · 1.46 KB
/
init.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
72
73
package main
import (
"flag"
"io"
"log"
"os"
"regexp"
)
func init() {
var err error
// command line flags
flag.StringVar(&cmdAddress, "address", "unix:/run/nginx-captcha.sock", `IP:PORT or Unix Socket path prefixd with "unix:"`)
flag.StringVar(&cmdDBPath, "db", "/var/cache/nginx-captcha/captcha.db", `path to CAPTCHA database`)
flag.UintVar(&cmdGenerate, "generate", 0, "specifies amount of unique CAPTHCAs to generate, zero has no action")
flag.BoolVar(&cmdLogDateTime, "log-date-time", true, "add date/time to log output")
flag.BoolVar(&cmdDebug, "debug", false, "enable debug logging")
flag.Parse()
// define custom log flags
var logFlag int
if cmdLogDateTime {
logFlag = log.Ldate | log.Ltime
} else {
logFlag = 0
}
// define debug log output
var debugWriter io.Writer
if cmdDebug {
debugWriter = os.Stdout
logFlag |= log.Lshortfile
} else {
debugWriter = io.Discard
}
// initialize loggers
Info = log.New(
os.Stdout,
"INFO: ",
logFlag,
)
Error = log.New(
os.Stderr,
"ERROR: ",
logFlag,
)
Debug = log.New(
debugWriter,
"DEBUG: ",
logFlag,
)
Bot = log.New(
os.Stdout,
"BOT: ",
logFlag,
)
// run generate CAPTCHA and exit
if cmdGenerate > 0 {
if err = generateCapcthaDB(cmdDBPath, cmdGenerate); err != nil {
Error.Fatalf("regexp compile error: %s\n", err.Error())
}
os.Exit(0)
}
reUUID, err = regexp.Compile(regExpUUIDv4)
if err != nil {
Error.Fatalf("regexp compile error: %s\n", err.Error())
}
}