-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
42 lines (35 loc) · 972 Bytes
/
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
package main
import (
"log/slog"
"net/http"
"os"
githubapptoken "github.com/shogo82148/actions-github-app-token/provider/github-app-token"
"github.com/shogo82148/aws-xray-yasdk-go/xray/xrayslog"
httplogger "github.com/shogo82148/go-http-logger"
"github.com/shogo82148/ridgenative"
)
var logger *slog.Logger
func init() {
// initialize the logger
h1 := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
})
h2 := xrayslog.NewHandler(h1, "trace_id")
logger = slog.New(h2)
slog.SetDefault(logger)
}
func main() {
h, err := githubapptoken.NewHandler()
if err != nil {
slog.Error("failed to initialize: %v", err)
os.Exit(1)
}
mux := http.NewServeMux()
mux.Handle("/", h)
logger := httplogger.NewSlogLogger(slog.LevelInfo, "http access log", logger)
err = ridgenative.ListenAndServe(":8080", httplogger.LoggingHandler(logger, mux))
if err != nil {
slog.Error("failed to listen and serve: %v", err)
os.Exit(1)
}
}