-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (35 loc) · 979 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
42
43
44
45
46
package main
import (
"devdiaries/api"
"devdiaries/api/middleware"
"devdiaries/database"
"fmt"
"net/http"
"github.com/lpernett/godotenv"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
//Register middleware
userRouter := r.PathPrefix("/user").Subrouter()
blogRouter := r.PathPrefix("/blog").Subrouter()
commentRouter := r.PathPrefix("/comment").Subrouter()
authRouter := r.PathPrefix("/").Subrouter()
indexRouter := r.PathPrefix("/").Subrouter()
userRouter.Use(middleware.AuthMiddleware)
blogRouter.Use(middleware.AuthMiddleware)
commentRouter.Use(middleware.AuthMiddleware)
api.RegisterUserRoutes(userRouter)
api.RegisterBlogRoutes(blogRouter)
api.RegisterCommentRoutes(commentRouter)
api.RegisterAuthRoutes(authRouter)
api.RegisterIndexRoutes(indexRouter)
godotenv.Load()
database.InitDB()
err := http.ListenAndServe("0.0.0.0:4000", r)
if err == nil {
fmt.Println("Server running successfully!")
} else {
panic(err)
}
}