-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (34 loc) · 944 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
package main
import (
"log/slog"
"net/http"
"os"
"time"
"github.com/JanStanleyWatt/hukubiki-api/api"
)
const TIMEOUT = 500 * time.Millisecond
func main() {
// slog初期化
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
slog.SetDefault(logger)
// サーバー初期化
logger.Info("Starting server...")
server := &http.Server{
Addr: ":8000",
ReadTimeout: TIMEOUT,
ReadHeaderTimeout: TIMEOUT,
Handler: http.TimeoutHandler(http.DefaultServeMux, TIMEOUT, "Timeout!"),
}
slog.Debug("server initialized",
"addr", server.Addr,
"readTimeoutMs", TIMEOUT,
"readHeaderTimeoutMs", TIMEOUT,
"handlerTimeoutMs", TIMEOUT)
// ルーティング定義
slog.Info("Registering handlers...")
http.HandleFunc("/int64/n", api.Int64n)
http.HandleFunc("/", api.Usage)
// サーバー起動
slog.Info("Server started.")
server.ListenAndServe()
}