kycnot.me/src/main.go

102 lines
2.3 KiB
Go
Raw Normal View History

2023-10-30 17:41:30 -04:00
package main
import (
"flag"
"os"
"github.com/joho/godotenv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
2023-10-30 17:42:11 -04:00
2023-11-12 16:06:22 -05:00
"pluja.dev/kycnot.me/config"
2023-10-30 17:42:11 -04:00
"pluja.dev/kycnot.me/database"
"pluja.dev/kycnot.me/server"
2024-01-27 00:42:12 -05:00
"pluja.dev/kycnot.me/utils/maintenance"
2023-11-12 16:06:22 -05:00
"pluja.dev/kycnot.me/utils/tos_scraper"
2023-10-30 17:41:30 -04:00
)
2023-11-12 16:06:22 -05:00
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")
)
2023-11-13 01:14:52 -05:00
func init() {
// Flags
flag.Parse()
2023-11-12 16:06:22 -05:00
config.Conf = config.Config{
Dev: *dev,
Cache: *nocache,
Debug: *debug,
Scraper: *scraper,
ListenAddr: *listen,
}
2023-10-30 17:41:30 -04:00
// Flags
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
2023-11-12 16:06:22 -05:00
log.Debug().Msg("Debug mode enabled")
2023-10-30 17:41:30 -04:00
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)
2023-11-12 16:06:22 -05:00
log.Debug().Msg("DEV mode enabled")
2023-10-30 17:41:30 -04:00
}
2023-11-12 16:06:22 -05:00
2023-10-30 17:41:30 -04:00
if *nocache {
2023-11-12 16:06:22 -05:00
log.Debug().Msg("Cache disabled")
2023-10-30 17:41:30 -04:00
}
// 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")
}
2024-02-10 07:47:44 -05:00
// Load donation addresses into config
config.Conf.Donations.Xmr = os.Getenv("XMR_ADDRESS")
config.Conf.Donations.Btc = os.Getenv("BTC_ADDRESS")
config.Conf.Donations.Lnn = os.Getenv("LNN_ADDRESS")
2023-10-30 17:41:30 -04:00
// Database init
log.Info().Msg("Initializing database.")
2024-01-27 00:42:12 -05:00
database.InitPocketbase()
2023-10-30 17:41:30 -04:00
2023-11-12 16:06:22 -05:00
// AI ToS Scraper init
if config.Conf.Scraper {
log.Info().Msg("Initializing AI ToS scraper.")
tos_scraper.InitTosScraperDaemon()
}
2024-01-27 00:42:12 -05:00
// Maintenance init
log.Info().Msg("Initializing maintenance daemon.")
maintenance.InitMaintenanceDaemon()
2023-11-13 01:14:52 -05:00
}
2023-11-12 16:06:22 -05:00
2023-11-13 01:14:52 -05:00
func main() {
2023-10-30 17:41:30 -04:00
// Server init
log.Info().Msg("Initializing server.")
2023-11-12 16:06:22 -05:00
server := server.NewServer(config.Conf.ListenAddr)
2024-01-27 00:42:12 -05:00
2023-11-12 16:06:22 -05:00
if err := server.Run(); err != nil {
log.Fatal().Err(err)
}
2023-10-30 17:41:30 -04:00
}