2017-06-30 21:10:25 +05:30
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-02-14 05:26:48 +05:30
|
|
|
"context"
|
|
|
|
"log/slog"
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
"github.com/spf13/cobra"
|
2024-02-14 05:26:48 +05:30
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2024-03-05 17:37:54 +05:30
|
|
|
"ely.by/chrly/internal/di"
|
2024-02-14 05:26:48 +05:30
|
|
|
"ely.by/chrly/internal/http"
|
|
|
|
"ely.by/chrly/internal/otel"
|
2017-06-30 21:10:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var serveCmd = &cobra.Command{
|
|
|
|
Use: "serve",
|
2020-01-03 03:21:57 +05:30
|
|
|
Short: "Starts HTTP handler for the skins system",
|
2024-02-07 18:59:52 +05:30
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2024-03-05 17:37:54 +05:30
|
|
|
return startServer(di.ModuleSkinsystem, di.ModuleProfiles, di.ModuleSigner)
|
2017-06-30 21:10:25 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(serveCmd)
|
|
|
|
}
|
2024-02-14 05:26:48 +05:30
|
|
|
|
|
|
|
func startServer(modules ...string) error {
|
|
|
|
container := shouldGetContainer()
|
|
|
|
|
|
|
|
var globalCtx context.Context
|
|
|
|
err := container.Resolve(&globalCtx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdownOtel, err := otel.SetupOTelSDK(globalCtx)
|
|
|
|
defer func() {
|
|
|
|
err := shutdownOtel(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
slog.Error("Unable to shutdown OpenTelemetry", slog.Any("error", err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var config *viper.Viper
|
|
|
|
err = container.Resolve(&config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Set("modules", modules)
|
|
|
|
|
|
|
|
err = container.Invoke(http.StartServer)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|