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
|
|
|
|
|
|
|
"pluja.dev/kycnot.me/database"
|
|
|
|
"pluja.dev/kycnot.me/server"
|
2023-10-30 17:41:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// 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")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Flags
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
if *debug {
|
|
|
|
log.Printf("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)
|
|
|
|
os.Setenv("DEV_MODE", "true")
|
|
|
|
os.Setenv("SCRAPER", "false")
|
|
|
|
log.Printf("DEV mode enabled")
|
|
|
|
}
|
|
|
|
if *nocache {
|
|
|
|
log.Printf("Cache disabled")
|
|
|
|
os.Setenv("CACHE", "false")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.")
|
2023-10-30 17:42:11 -04:00
|
|
|
database.InitDb()
|
|
|
|
defer database.Close()
|
2023-10-30 17:41:30 -04:00
|
|
|
|
|
|
|
// Server init
|
|
|
|
log.Info().Msg("Initializing server.")
|
2023-10-30 17:42:11 -04:00
|
|
|
server := server.NewServer(os.Getenv("LISTEN_ADDR"))
|
|
|
|
server.Run()
|
2023-10-30 17:41:30 -04:00
|
|
|
}
|