-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (45 loc) · 1.22 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
package main
import (
"fmt"
"os"
"time"
"github.com/gouline/blaster/internal/pkg/server"
zaplogfmt "github.com/sykesm/zap-logfmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
debug := os.Getenv("DEBUG") == "1"
var logger *zap.Logger
if debug {
logger = zap.Must(zap.NewDevelopment())
} else {
loggerConfig := zap.NewProductionEncoderConfig()
loggerConfig.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
encoder.AppendString(ts.UTC().Format(time.RFC3339))
}
logger = zap.New(zapcore.NewCore(
zaplogfmt.NewEncoder(loggerConfig),
os.Stdout,
zapcore.DebugLevel,
))
}
defer logger.Sync()
s, err := server.New(server.Config{
Logger: logger,
Debug: debug,
Host: os.Getenv("HOST"),
Port: os.Getenv("PORT"),
CertFile: os.Getenv("CERT_FILE"),
KeyFile: os.Getenv("KEY_FILE"),
StaticRoot: "static",
TemplatesRoot: "templates",
SlackClientID: os.Getenv("SLACK_CLIENT_ID"),
SlackClientSecret: os.Getenv("SLACK_CLIENT_SECRET"),
})
if err != nil {
panic(fmt.Sprintf("failed to create server: %s", err))
}
err = s.Start()
logger.Fatal("server stopped", zap.Error(err))
}