-
Notifications
You must be signed in to change notification settings - Fork 1
/
deps.go
71 lines (60 loc) · 1.62 KB
/
deps.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
package main
import (
"context"
"fmt"
avcontrol "github.com/byuoitav/av-control-api"
"github.com/byuoitav/av-control-api/couch"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func dataService(ctx context.Context, config dataServiceConfig) avcontrol.DataService {
var opts []couch.Option
var url string
if config.Insecure {
url = "http://" + config.Addr
} else {
url = "https://" + config.Addr
}
if len(config.Username) > 0 {
opts = append(opts, couch.WithBasicAuth(config.Username, config.Password))
}
ds, err := couch.New(ctx, url, opts...)
if err != nil {
panic(fmt.Sprintf("unable to setup couch: %s", err))
}
return ds
}
func logger(logLevel string) (zap.Config, *zap.Logger) {
var level zapcore.Level
if err := level.Set(logLevel); err != nil {
panic(fmt.Sprintf("invalid log level: %s", err))
}
config := zap.Config{
Level: zap.NewAtomicLevelAt(level),
Sampling: &zap.SamplingConfig{
Initial: 100,
Thereafter: 100,
},
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{
TimeKey: "@",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "trace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
log, err := config.Build()
if err != nil {
panic(fmt.Sprintf("unable to build logger: %s", err))
}
return config, log
}