summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorLizzy Hunt <lizzy.hunt@usu.edu>2024-03-26 16:00:05 -0600
committerLizzy Hunt <lizzy.hunt@usu.edu>2024-03-26 16:00:05 -0600
commitfe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb (patch)
tree6111f03c2da4eb42aff03cda72157a8961da27e8 /main.go
parent27aab70386c68f3a0f22c52e72b91cf16b289100 (diff)
downloadhatecomputers.club-fe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb.tar.gz
hatecomputers.club-fe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb.zip
initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..2d7771b
--- /dev/null
+++ b/main.go
@@ -0,0 +1,44 @@
+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"
+ "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.Server {
+ server := api.MakeServer(argv, dbConn)
+ log.Println("server listening on port", argv.Port)
+ err = server.ListenAndServe()
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+}