phoneof/main.go
Elizabeth Hunt f163a24279
All checks were successful
continuous-integration/drone/push Build is passing
initial commit
2025-01-03 01:47:07 -08:00

64 lines
1.1 KiB
Go

package main
import (
"fmt"
"log"
"net/http"
"git.simponic.xyz/simponic/phoneof/api"
"git.simponic.xyz/simponic/phoneof/args"
"git.simponic.xyz/simponic/phoneof/database"
"git.simponic.xyz/simponic/phoneof/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 {
go func() {
scheduler.StartScheduler(dbConn, argv)
}()
}
if argv.Server {
mux := api.MakeMux(argv, dbConn)
log.Println("🚀🚀 phoneof API listening on port", argv.Port)
go func() {
server := &http.Server{
Addr: ":" + fmt.Sprint(argv.Port),
Handler: mux,
}
err = server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}()
}
if argv.Server || argv.Scheduler {
select {} // block forever
}
}