http and common
This commit is contained in:
+11
-21
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
||||
redisinv "git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
||||
"git.k6n.net/mats/platform/config"
|
||||
"git.k6n.net/mats/platform/httpserver"
|
||||
"git.k6n.net/mats/platform/rabbit"
|
||||
"git.k6n.net/mats/platform/tax"
|
||||
"github.com/adyen/adyen-go-api-library/v21/src/adyen"
|
||||
@@ -293,35 +293,25 @@ func main() {
|
||||
w.Write([]byte("1.0.0"))
|
||||
})
|
||||
|
||||
// Debug mux on separate port (metrics + pprof).
|
||||
go http.ListenAndServe(":8081", debugMux)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: ":8080",
|
||||
BaseContext: func(net.Listener) context.Context { return ctx },
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 20 * time.Second,
|
||||
Handler: otelhttp.NewHandler(mux, "/"),
|
||||
}
|
||||
|
||||
defer func() {
|
||||
fmt.Println("Shutting down due to signal")
|
||||
otelShutdown(context.Background())
|
||||
diskStorage.Close()
|
||||
pool.Close()
|
||||
}()
|
||||
|
||||
srvErr := make(chan error, 1)
|
||||
go func() {
|
||||
srvErr <- srv.ListenAndServe()
|
||||
}()
|
||||
|
||||
log.Print("Checkout server started at port 8080")
|
||||
|
||||
go http.ListenAndServe(":8081", debugMux)
|
||||
|
||||
select {
|
||||
case err = <-srvErr:
|
||||
log.Fatalf("Unable to start server: %v", err)
|
||||
case <-ctx.Done():
|
||||
stop()
|
||||
if err := httpserver.RunServerWithShutdown(srv, "checkout", 15*time.Second, 5*time.Second,
|
||||
func(context.Context) error { stop(); return nil },
|
||||
func(context.Context) error { otelShutdown(context.Background()); return nil },
|
||||
func(context.Context) error { diskStorage.Close(); return nil },
|
||||
func(context.Context) error { pool.Close(); return nil },
|
||||
); err != nil {
|
||||
log.Fatalf("server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user