watchDB/cmd/site/main.go
2024-08-03 09:28:23 +02:00

42 lines
825 B
Go

package main
import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"git.clustercockpit.org/moebiusband/go-http-skeleton/internal/util"
"git.clustercockpit.org/moebiusband/go-http-skeleton/web"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("Starting http server")
defer logger.Info("Stopping http server")
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
if err := run(ctx); err != nil {
logger.Error("Error running http server", slog.Any("err", err))
os.Exit(1)
}
}
func run(ctx context.Context) error {
eg := util.NewErrGroupSharedCtx(
ctx,
web.RunBlocking(8080),
)
if err := eg.Wait(); err != nil {
return fmt.Errorf("error running http server: %w", err)
}
return nil
}