New: ServiceBase migrated from shortener

This commit is contained in:
2026-06-04 22:14:42 +02:00
parent 36267b0bba
commit de9ddabd8c
7 changed files with 342 additions and 0 deletions

27
server/server.go Normal file
View File

@@ -0,0 +1,27 @@
package server
import (
"log/slog"
"net/http"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
// ListenAndServeH2C starts an HTTP server with HTTP/1.1 and unencrypted HTTP/2 support (h2c),
// wrapped with OpenTelemetry HTTP handler for tracing and metrics.
func ListenAndServeH2C(addr string, handler http.Handler, telemetryName string) error {
instrumentedHandler := otelhttp.NewHandler(handler, telemetryName)
p := new(http.Protocols)
p.SetHTTP1(true)
// Use h2c so we can serve HTTP/2 without TLS.
p.SetUnencryptedHTTP2(true)
s := http.Server{
Addr: addr,
Handler: instrumentedHandler,
Protocols: p,
}
slog.Info("Starting server on " + addr)
return s.ListenAndServe()
}