-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 955 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
package main
import (
"log"
"net/http"
"portfolio/controller"
"portfolio/db"
"portfolio/models"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func main() {
loadEnvVars()
connectToDatabase()
http.ListenAndServe(":8000", getRouters())
}
func connectToDatabase() {
db.Connect()
db.Database.AutoMigrate(&models.Project{})
}
func loadEnvVars() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
}
func getRouters() *mux.Router {
routers := mux.NewRouter()
routers.StrictSlash(true)
routers.HandleFunc("/projects", controller.CreateProject).Methods("POST")
routers.HandleFunc("/projects", controller.ListProjects).Methods("GET")
routers.HandleFunc("/projects/{id}", controller.RetrieveProject).Methods("GET")
routers.HandleFunc("/projects/{id}", controller.DeleteProject).Methods("DELETE")
routers.HandleFunc("/projects/{id}", controller.UpdateProject).Methods("PATCH")
return routers
}