-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
96 lines (83 loc) · 2.23 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"flag"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/magnusfurugard/multi-john/howdy"
"github.com/magnusfurugard/multi-john/worker"
"go.etcd.io/etcd/clientv3"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var mode string
var logLevel string
var johnFile string
var johnFlags string
func init() {
flag.StringVar(&mode, "mode", "worker", "mode to start in, must be worker or howdy")
flag.StringVar(&logLevel, "logLevel", "info", "log level, info or debug")
flag.StringVar(&johnFile, "johnFile", "dummy", "the file with hashes to process")
flag.StringVar(&johnFlags, "johnFlags", "", "a comma-separated list of flags to pass, e.g. --format=raw-sha256,--fork=2")
}
func GetLogLevel() zapcore.Level {
if strings.ToLower(logLevel) == "debug" {
return zapcore.DebugLevel
}
return zapcore.InfoLevel
}
func main() {
flag.Parse()
// Logger
logger, _ := zap.Config{
Encoding: "json",
Level: zap.NewAtomicLevelAt(GetLogLevel()),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "message",
LevelKey: "level",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "time",
EncodeTime: zapcore.ISO8601TimeEncoder,
CallerKey: "caller",
EncodeCaller: zapcore.ShortCallerEncoder,
},
}.Build()
defer logger.Sync() // flushes buffer, if any
sugar := logger.Sugar()
// Find etcd
endpoint := []string{}
if s, ok := os.LookupEnv("ETCD_ADVERTISE_CLIENT_URLS"); ok {
endpoint = append(endpoint, strings.Split(s, ",")...)
} else {
endpoint = append(endpoint, "localhost:2379")
//sugar.Panicf("found no advertised client urls for etcd")
}
sugar.Info("connect to etcd...")
cli, err := clientv3.New(clientv3.Config{
Endpoints: endpoint,
DialTimeout: 10 * time.Second,
})
if err != nil {
sugar.Panic(err)
}
defer cli.Close()
switch mode {
case "howdy":
s := howdy.New(8080, logger, cli)
go s.Serve()
case "worker":
err := worker.New(logger, cli, johnFile, johnFlags)
if err != nil {
sugar.Panic(err)
}
default:
sugar.Panicf("`%v` is not a valid mode", mode)
}
termChan := make(chan os.Signal)
signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM)
<-termChan
}