Interactive/pkg/cmd/main.go

53 lines
1.3 KiB
Go
Raw Normal View History

2024-02-01 15:26:17 +00:00
package main
import (
"code.smartsheep.studio/hydrogen/interactive/pkg/server"
"os"
"os/signal"
"syscall"
interactive "code.smartsheep.studio/hydrogen/interactive/pkg"
"code.smartsheep.studio/hydrogen/interactive/pkg/database"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
func init() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
}
func main() {
// Configure settings
viper.AddConfigPath(".")
viper.AddConfigPath("..")
viper.SetConfigName("settings")
viper.SetConfigType("toml")
// Load settings
if err := viper.ReadInConfig(); err != nil {
log.Panic().Err(err).Msg("An error occurred when loading settings.")
}
// Connect to database
if err := database.NewSource(); err != nil {
log.Fatal().Err(err).Msg("An error occurred when connect to database.")
} else if err := database.RunMigration(database.C); err != nil {
log.Fatal().Err(err).Msg("An error occurred when running database auto migration.")
}
// Server
server.NewServer()
go server.Listen()
// Messages
2024-02-01 16:53:22 +00:00
log.Info().Msgf("Interactive v%s is started...", interactive.AppVersion)
2024-02-01 15:26:17 +00:00
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
2024-02-01 16:53:22 +00:00
log.Info().Msgf("Interactive v%s is quitting...", interactive.AppVersion)
2024-02-01 15:26:17 +00:00
}