-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
27 lines (23 loc) · 887 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
package main
import (
"fmt"
"net/http"
"github.com/denizedizcan/REST-API-User-Management-Service/db"
"github.com/denizedizcan/REST-API-User-Management-Service/handlers"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
// start the app and handle routes
func main() {
fmt.Println("Starting App..")
godotenv.Load()
DB := db.Init()
h := handlers.New(DB)
router := mux.NewRouter()
router.HandleFunc("/users", handlers.SetMiddlewareJSON(h.CreateUser)).Methods("PUT")
router.HandleFunc("/users/{id}", handlers.SetMiddlewareJSON(h.UpdateUser)).Methods("PATCH")
router.HandleFunc("/users/{id}", handlers.SetMiddlewareJSON(h.DeleteUser)).Methods("DELETE")
router.HandleFunc("/users/{id}", handlers.SetMiddlewareJSON(h.ShowUser)).Methods("GET")
router.HandleFunc("/users", handlers.SetMiddlewareJSON(h.ShowAllUsers)).Methods("GET")
http.ListenAndServe(":8080", router)
}