2024-03-26 18:00:05 -04:00
|
|
|
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"
|
2024-04-02 18:26:39 -04:00
|
|
|
"git.hatecomputers.club/hatecomputers/hatecomputers.club/hcdns"
|
2024-03-27 17:10:39 -04:00
|
|
|
"git.hatecomputers.club/hatecomputers/hatecomputers.club/scheduler"
|
2024-03-26 18:00:05 -04:00
|
|
|
"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")
|
|
|
|
}
|
|
|
|
|
2024-03-27 17:10:39 -04:00
|
|
|
if argv.Scheduler {
|
|
|
|
scheduler.StartScheduler(dbConn)
|
|
|
|
}
|
|
|
|
|
2024-03-26 18:00:05 -04:00
|
|
|
if argv.Server {
|
|
|
|
server := api.MakeServer(argv, dbConn)
|
2024-03-28 16:58:07 -04:00
|
|
|
log.Println("🚀🚀 API listening on port", argv.Port)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err = server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2024-03-26 18:00:05 -04:00
|
|
|
}
|
2024-03-28 16:58:07 -04:00
|
|
|
|
|
|
|
if argv.Dns {
|
2024-04-02 18:26:39 -04:00
|
|
|
server := hcdns.MakeServer(argv, dbConn)
|
2024-03-28 16:58:07 -04:00
|
|
|
log.Println("🚀🚀 DNS resolver listening on port", argv.DnsPort)
|
|
|
|
go func() {
|
|
|
|
err = server.ListenAndServe()
|
2024-05-12 17:32:50 -04:00
|
|
|
|
2024-03-28 16:58:07 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2024-05-12 17:20:47 -04:00
|
|
|
}
|
2024-03-28 16:58:07 -04:00
|
|
|
|
2024-05-12 17:20:47 -04:00
|
|
|
if argv.Dns || argv.Server {
|
2024-04-24 15:46:34 -04:00
|
|
|
select {}
|
|
|
|
}
|
2024-05-12 17:20:47 -04:00
|
|
|
|
|
|
|
log.Println("no services started")
|
2024-03-26 18:00:05 -04:00
|
|
|
}
|