-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
53 lines (44 loc) · 1.15 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
package main
import (
"log"
"pet-pal/api/config"
"pet-pal/api/controllers"
"pet-pal/api/middleware"
"github.com/gin-gonic/gin"
)
func main() {
// Initialize database connection
db := config.InitDb()
// Initialize Auth0 token validator
validator, err := config.NewAuth0JWTValidator()
if err != nil {
log.Fatalf("Failed to set up the jwt validator")
}
router := gin.Default()
router.LoadHTMLGlob("templates/*")
router.Static("/static", "./static")
router.GET("/", controllers.ServeSwaggerUI)
router.GET("/ping", controllers.Ping)
api := router.Group("/api")
{
api.Use(middleware.EnsureValidToken(validator))
pets := api.Group("/pets")
{
pets.GET("/", controllers.GetPets(db))
pets.POST("/", controllers.PostPet(db))
pets.GET("/:petId", controllers.GetPet(db))
pets.PUT("/:petId", controllers.PutPet(db))
pets.DELETE("/:petId", controllers.DeletePet(db))
}
species := api.Group("/species")
{
species.GET("/:speciesId", controllers.GetSpecies(db))
}
breeds := api.Group("/breeds")
{
breeds.GET("/", controllers.GetBreeds(db))
breeds.GET("/:breedId", controllers.GetBreed(db))
}
}
router.Run(":3000")
}