nurse/cmd/server.go
Peter Kurfer 0faff1d481
Some checks failed
Renovate / renovate (push) Successful in 1m8s
Go build / build (push) Failing after 2m3s
chore: cleanup, add docs, refactor some quirks and prepare release
2023-12-04 16:59:10 +01:00

45 lines
856 B
Go

package cmd
import (
"context"
"errors"
"log/slog"
"net"
"net/http"
"github.com/urfave/cli/v2"
"code.icb4dc0.de/prskr/nurse/api"
)
type server struct {
*app
}
func (a *server) RunServer(ctx *cli.Context) error {
logger := slog.Default()
mux, err := api.PrepareMux(a.nurseInstance, a.registry, a.lookup)
if err != nil {
logger.Error("Failed to prepare server mux", slog.String("err", err.Error()))
}
srv := http.Server{
Addr: ctx.String(httpAddressFlag),
ReadHeaderTimeout: ctx.Duration(httpReadHeaderTimeout),
BaseContext: func(listener net.Listener) context.Context {
return ctx.Context
},
Handler: mux,
}
if err := srv.ListenAndServe(); err != nil {
if errors.Is(err, http.ErrServerClosed) {
return nil
}
logger.Error("Failed to serve HTTP", slog.String("err", err.Error()))
}
return nil
}