package cmd import ( "apjournal/config" database "apjournal/internal/database/sql" "apjournal/internal/server" "os" "log/slog" "github.com/spf13/cobra" "github.com/spf13/viper" ) func init() { rootCmd.AddCommand(startCmd) } var startCmd = &cobra.Command{ Use: "start", Short: "Start data server", Long: `Start data server`, Run: func(cmd *cobra.Command, args []string) { log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug, AddSource: true})) // load server configuration from server if viper.ConfigFileUsed() != "" { log.Debug("Configuration file loaded", "section", "init", "path", viper.ConfigFileUsed()) } cfg := config.LoadConfig(viper.GetViper()) db, err := database.Init(cfg.DBURI) if err != nil { log.Error("failed to connect to db", "error", err) return } srv := server.NewServer(cfg, log, db.Conn) // listen for new messages srv.Listen() }, }