-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (34 loc) · 1.12 KB
/
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
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"github.com/Marcusk19/stubber/controller"
)
type Movie struct {
ID string `json:"Id"`
Title string `json:"Title"`
Desc string `json:"desc"`
Rating string `json:"rating"`
}
func handleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
// myRouter.HandleFunc("/", homePage)
myRouter.HandleFunc("/api/v1/movies", controller.MoviesByRating).Methods("GET")
myRouter.HandleFunc("/api/v1/movies/{id}", controller.GetMovie).Methods("GET")
myRouter.HandleFunc("/api/v1/movies", controller.InsertMovie).Methods("POST", "OPTIONS")
myRouter.HandleFunc("/api/v1/movies", controller.UpdateMovie).Methods("POST")
myRouter.HandleFunc("/api/v1/movies/delete/{id}", controller.DeleteMovie).Methods("DELETE", "OPTIONS")
myRouter.HandleFunc("/upload", controller.UploadFile)
log.Fatal(http.ListenAndServe(":9876", myRouter))
}
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file", err)
}
log.Print("[INFO] .env file loaded")
log.Print("[INFO] server starting...")
handleRequests()
}