hatecomputers.club/main.go

50 lines
1.0 KiB
Go

package main
import (
"log"
"git.hatecomputers.club/hatecomputers/hatecomputers.club/api"
"git.hatecomputers.club/hatecomputers/hatecomputers.club/args"
"git.hatecomputers.club/hatecomputers/hatecomputers.club/database"
"git.hatecomputers.club/hatecomputers/hatecomputers.club/scheduler"
"github.com/joho/godotenv"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
err := godotenv.Load()
if err != nil {
log.Println("could not load .env file:", err)
}
argv, err := args.GetArgs()
if err != nil {
log.Fatal(err)
}
dbConn := database.MakeConn(&argv.DatabasePath)
defer dbConn.Close()
if argv.Migrate {
_, err = database.Migrate(dbConn)
if err != nil {
log.Fatal(err)
}
log.Println("database migrated successfully")
}
if argv.Scheduler {
scheduler.StartScheduler(dbConn)
}
if argv.Server {
server := api.MakeServer(argv, dbConn)
err = server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
log.Println("🚀🚀 server listening on port", argv.Port)
}
}