-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
44 lines (37 loc) · 837 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"log"
"net/http"
"os"
"tectonic-api/database"
"tectonic-api/routes"
)
// @title Tectonic API
// @version 0.1
// @description Functionality provider for Tectonic guild.
// @host localhost:8080
// @BasePath /api
func main() {
conn, err := database.InitDB()
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing database: %v\n", err)
os.Exit(1)
}
defer conn.Close()
err = database.RunMigrations(conn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error running migrations: %v\n", err)
os.Exit(1)
}
router := routes.NewAPIBuilder().AttachV1Routes()
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
fmt.Println("Server will listen on port:", port)
err = http.ListenAndServe(":"+port, router)
if err != nil {
log.Fatalf("Server failed to start: %v", err)
}
}