-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
41 lines (35 loc) · 957 Bytes
/
server.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
package probot
import (
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"github.com/spf13/pflag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type ServerOptions struct {
Address string
Port int
Path string
}
func (opts *ServerOptions) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&opts.Address, "address", "127.0.0.1", "Address listen on")
flags.IntVar(&opts.Port, "port", 7771, "Port listen on")
flags.StringVar(&opts.Path, "path", "/hook", "Path listen on")
}
type loggerOptions struct {
logger logr.Logger
}
func (opts *loggerOptions) AddFlags(flags *pflag.FlagSet) {
// TODO: Add log flags
logconfig := zap.NewDevelopmentConfig()
logconfig.Encoding = "console"
logconfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
zlogger, err := logconfig.Build()
if err != nil {
panic(err)
}
opts.logger = zapr.NewLogger(zlogger)
}
func (opts *loggerOptions) GetLogger() logr.Logger {
return opts.logger
}