-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (50 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
51
52
53
54
55
56
57
58
59
60
package main
import (
"errors"
"log"
"net/http"
"time"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
_ "github.com/go-sql-driver/mysql"
db "github.com/nekochans/lgtm-cat-api/db/sqlc"
"github.com/nekochans/lgtm-cat-api/handler"
"github.com/nekochans/lgtm-cat-api/infrastructure"
)
var (
uploader *manager.Uploader
queries *db.Queries
logger infrastructure.Logger
release string
)
func main() {
queries = infrastructure.NewSqlcQueries()
uploader = infrastructure.NewUploader()
logger = infrastructure.NewLogger()
validator, err := infrastructure.NewJwtValidator()
if err != nil {
logger.Error(err)
}
r := handler.NewRouter(uploader, queries, logger, validator)
if err := infrastructure.InitSentry(release); err != nil {
logger.Error(err)
}
const timeoutSecond = 10
server := &http.Server{
Addr: ":3333",
Handler: r,
ReadHeaderTimeout: timeoutSecond * time.Second,
ErrorLog: log.New(&logForwarder{l: logger}, "", 0),
}
err = server.ListenAndServe()
if err != nil {
logger.Error(err)
return
}
}
type logForwarder struct {
l infrastructure.Logger
}
func (fw *logForwarder) Write(p []byte) (int, error) {
fw.l.Error(errors.New(string(p)))
return len(p), nil
}