-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
32 lines (25 loc) · 679 Bytes
/
server.go
File metadata and controls
32 lines (25 loc) · 679 Bytes
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
package main
import (
"log/slog"
"net/http"
"time"
)
func newServer(app *App) (*http.Server, <-chan error) {
log := app.log
srv := &http.Server{
Addr: app.address,
ReadHeaderTimeout: 3 * time.Second,
ReadTimeout: 6 * time.Second,
WriteTimeout: 9 * time.Second,
IdleTimeout: 60 * time.Second,
MaxHeaderBytes: http.DefaultMaxHeaderBytes, // Default is 1MB.
Handler: app.handler(),
ErrorLog: slog.NewLogLogger(log.Handler(), slog.LevelDebug),
}
errChan := make(chan error, 1)
go func() {
log.Info("listens on", "address", app.address)
errChan <- srv.ListenAndServe()
}()
return srv, errChan
}