54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"os/signal"
|
||
|
"syscall"
|
||
|
|
||
|
passport "code.smartsheep.studio/hydrogen/passport/pkg"
|
||
|
"code.smartsheep.studio/hydrogen/passport/pkg/database"
|
||
|
"code.smartsheep.studio/hydrogen/passport/pkg/server"
|
||
|
"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("yaml")
|
||
|
|
||
|
// 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.")
|
||
|
}
|
||
|
|
||
|
// Create connection between bus
|
||
|
server.InitConnection(viper.GetString("host"), viper.GetString("id"))
|
||
|
server.PublishCommands(server.C)
|
||
|
go server.C.ListenToServer()
|
||
|
|
||
|
// Messages
|
||
|
log.Info().Msgf("Passport v%s is started...", passport.AppVersion)
|
||
|
|
||
|
quit := make(chan os.Signal, 1)
|
||
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||
|
<-quit
|
||
|
|
||
|
log.Info().Msgf("Passport v%s is quitting...", passport.AppVersion)
|
||
|
}
|