This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
43 lines (37 loc) · 1.39 KB
/
server.go
File metadata and controls
43 lines (37 loc) · 1.39 KB
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
package server
import (
"context"
"fmt"
"net"
"net/http"
"time"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"github.com/x-ethr/server/internal/writer"
)
// Server initializes a http.Server with application-specific configuration.
func Server(ctx context.Context, handler http.Handler, middleware *Middlewares, port string) *http.Server {
handler = writer.Handle(middleware.Handler(handler))
if v, ok := ctx.Value("server-name").(string); ok {
handler = otelhttp.NewHandler(handler, "server", otelhttp.WithServerName(v), otelhttp.WithMessageEvents(otelhttp.ReadEvents, otelhttp.WriteEvents))
} else {
handler = otelhttp.NewHandler(handler, "server", otelhttp.WithMessageEvents(otelhttp.ReadEvents, otelhttp.WriteEvents))
}
return &http.Server{
Addr: fmt.Sprintf("0.0.0.0:%s", port),
Handler: handler,
DisableGeneralOptionsHandler: false,
TLSConfig: nil,
ReadTimeout: 15 * time.Second,
ReadHeaderTimeout: 0,
WriteTimeout: 60 * time.Second,
IdleTimeout: 30 * time.Second,
MaxHeaderBytes: http.DefaultMaxHeaderBytes,
TLSNextProto: nil,
ConnState: nil,
ErrorLog: nil,
BaseContext: func(net.Listener) context.Context {
return ctx
},
ConnContext: nil,
}
}