-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (47 loc) · 1.45 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
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"log"
"net/http"
"github.com/go-chi/chi"
chiMiddleWare "github.com/go-chi/chi/middleware"
"postman-twitter/config"
"postman-twitter/database"
"postman-twitter/util"
"postman-twitter/middleware"
"postman-twitter/endpoints"
"postman-twitter/redis"
)
const (
AUTH_REQ bool = true
AUTH_NOT_REQ bool = false
)
func routes() chi.Router {
router := chi.NewRouter()
router.Get("/ping", middleware.ResponseWrapper(Ping, AUTH_NOT_REQ))
router.Route("/user", func(r chi.Router) {
r.Post("/{userID}/follow", middleware.ResponseWrapper(endpoints.FollowHandler, AUTH_REQ))
r.Post("/{userID}/unfollow", middleware.ResponseWrapper(endpoints.UnFollowHandler, AUTH_REQ))
})
router.Route("/auth", func(r chi.Router) {
r.Post("/signup", middleware.ResponseWrapper(endpoints.SignUpHandler, AUTH_NOT_REQ))
r.Post("/signin", middleware.ResponseWrapper(endpoints.SignInHandler, AUTH_NOT_REQ))
r.Post("/signout", middleware.ResponseWrapper(endpoints.LogOutHandler, AUTH_REQ))
})
return router
}
func main() {
config.Init()
database.Init()
redis.Init()
defer database.DB.Close()
router := chi.NewRouter()
router.Use(chiMiddleWare.Logger)
router.Mount("/api/v1", routes())
fmt.Println("Running on " + config.ServerConfig.Port)
log.Fatal(http.ListenAndServe(":" + config.ServerConfig.Port, router))
}
//HealhCheck API
func Ping(r *http.Request) (interface{}, *util.HTTPError) {
return "Pong", nil
}