package main import ( "flag" "os" "github.com/joho/godotenv" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "pluja.dev/kycnot.me/config" "pluja.dev/kycnot.me/database" "pluja.dev/kycnot.me/server" "pluja.dev/kycnot.me/utils/tos_scraper" ) var ( // Flags debug = flag.Bool("debug", false, "sets log level to debug") dev = flag.Bool("dev", false, "sets dev mode") nocache = flag.Bool("nocache", false, "disables cache") scraper = flag.Bool("scrap", false, "enables the scraper") listen = flag.String("listen", ":4488", "address to listen to") ) func init() { // Flags flag.Parse() config.Conf = config.Config{ Dev: *dev, Cache: *nocache, Debug: *debug, Scraper: *scraper, ListenAddr: *listen, } // Flags log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) zerolog.SetGlobalLevel(zerolog.InfoLevel) if *debug { log.Debug().Msg("Debug mode enabled") log.Logger = log.Output( zerolog.ConsoleWriter{ Out: os.Stdout, TimeFormat: "02.01.2006 15:04:05", }, ).With().Caller().Logger() zerolog.SetGlobalLevel(zerolog.DebugLevel) } if *dev { log.Logger = log.Output( zerolog.ConsoleWriter{ Out: os.Stdout, TimeFormat: "02.01.2006 15:04:05", }, ).With().Caller().Logger() zerolog.SetGlobalLevel(zerolog.DebugLevel) log.Debug().Msg("DEV mode enabled") } if *nocache { log.Debug().Msg("Cache disabled") } // Load .env file log.Info().Msg("Loading .env file.") err := godotenv.Load() if err != nil { log.Info().Msg("No .env file found, using environment variables") } // Database init log.Info().Msg("Initializing database.") database.InitDb() // AI ToS Scraper init if config.Conf.Scraper { log.Info().Msg("Initializing AI ToS scraper.") tos_scraper.InitTosScraperDaemon() } } func main() { // Server init log.Info().Msg("Initializing server.") defer database.Close() server := server.NewServer(config.Conf.ListenAddr) if err := server.Run(); err != nil { log.Fatal().Err(err) } }