package main import ( "github.com/joho/godotenv" _ "github.com/lib/pq" "holiday-api/api" "holiday-api/db" "holiday-api/migration" "io/fs" "log" "net/http" "os" "strings" ) func init() { godotenv.Load() log.SetPrefix("") log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) } func main() { db, err := connectToDb() if err != nil { log.Fatalf("couldn't connect to db: %v", err) } if err := migration.InitializeMigrations(db, migrationFolder()); err != nil { log.Fatalf("couldn't execute migrations: %v", err) } server := api.SetupServer(db) log.Fatal(http.ListenAndServe(":5281", server)) } func hasProfile(value string) bool { profileOptions := strings.Split(os.Getenv("PROFILE"), ",") for _, option := range profileOptions { if option == value { return true } } return false } func migrationFolder() fs.FS { if hasProfile("dev") { return db.DevMigrations } return db.ProdMigrations }