package main

import (
	"context"
	"log"
	"os"
	"os/signal"
	"syscall"

	"sub2api-cn-relay-manager/internal/app"
)

func main() {
	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer stop()

	if err := run(ctx, app.Bootstrap, func(ctx context.Context, server *app.Server) error {
		return server.Run(ctx)
	}); err != nil {
		log.Fatalf("run server: %v", err)
	}
}

func run(ctx context.Context, bootstrap func(context.Context) (*app.Server, error), runServer func(context.Context, *app.Server) error) error {
	server, err := bootstrap(ctx)
	if err != nil {
		return err
	}

	return runServer(ctx, server)
}
