-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (29 loc) · 1.38 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
package main // import "github.com/keidrun/boilerplate-gorilla-mux-for-rest-api-with-jwt"
import (
"fmt"
"log"
"net/http"
"github.com/keidrun/boilerplate-gorilla-mux-for-rest-api-with-jwt/config"
"github.com/keidrun/boilerplate-gorilla-mux-for-rest-api-with-jwt/controllers"
"github.com/keidrun/boilerplate-gorilla-mux-for-rest-api-with-jwt/driver"
"github.com/subosito/gotenv"
"github.com/gorilla/mux"
)
func init() {
gotenv.Load()
}
func main() {
conf := config.GetConfig()
db := driver.ConnectDB()
controller := controllers.Controller{}
router := mux.NewRouter()
router.HandleFunc("/signup", controller.Signup(db)).Methods("POST")
router.HandleFunc("/login", controller.Login(db)).Methods("POST")
router.HandleFunc("/api/users", controller.TokenVerifyMiddleWare(controller.GetUsers(db))).Methods("GET")
router.HandleFunc("/api/users/{id}", controller.TokenVerifyMiddleWare(controller.GetUser(db))).Methods("GET")
router.HandleFunc("/api/users", controller.TokenVerifyMiddleWare(controller.AddUser(db))).Methods("POST")
router.HandleFunc("/api/users/{id}", controller.TokenVerifyMiddleWare(controller.UpdateUser(db))).Methods("PUT")
router.HandleFunc("/api/users/{id}", controller.TokenVerifyMiddleWare(controller.RemoveUser(db))).Methods("DELETE")
log.Printf("Server up on port %v....\n", conf.Port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", conf.Port), router))
}