-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.go
94 lines (81 loc) · 2.29 KB
/
routes.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"github.com/DevEdification/v2/controllers"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"log"
"net/http"
_ "github.com/DevEdification/v2/docs"
)
// @title Amozone API
// @version 2.0
// @description Swagger page for Amozone Golang API.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email hunterhartline87@gmail.com
// @license.name MIT
// @license.url "/LICENSE"
// @host localhost:8080
// @BasePath /api/v1
// @query.collection.format multi
func initRoutes() {
// Init gin engine
r := initGin()
//c := controller.NewController()
v1 := r.Group("/api/v1")
{
// Book routes
books := v1.Group("/books")
{
books.GET(":id", controllers.FindBook)
books.GET("", controllers.FindBooks)
books.POST("", controllers.CreateBook)
books.PATCH(":id", controllers.UpdateBook)
books.DELETE(":id", controllers.DeleteBook)
}
// Website routes
websites := v1.Group("/websites")
{
websites.GET(":id", controllers.FindWebsite)
websites.GET("", controllers.FindWebsites)
websites.POST("", controllers.CreateWebsite)
websites.PATCH(":id", controllers.UpdateWebsite)
websites.DELETE(":id", controllers.DeleteWebsite)
}
// VizNug routes
viznugs := v1.Group("/viznugs")
{
viznugs.GET(":id", controllers.FindVizNug)
viznugs.GET("", controllers.FindVizNugs)
viznugs.POST("", controllers.CreateVizNug)
viznugs.PATCH(":id", controllers.UpdateVizNug)
viznugs.DELETE(":id", controllers.DeleteVizNug)
}
// User routes
users := v1.Group("/users")
{
users.GET(":id", controllers.FindUser)
users.GET(":id/login", controllers.Login)
users.POST("", controllers.CreateUser)
users.PATCH(":id", controllers.UpdateUser)
users.DELETE(":id", controllers.DeleteUser)
}
}
// Swagger API route
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
// attach router to server - handle errors
err := r.Run()
if err != nil {
log.Fatalln(err)
}
}
// initGin initialize gin engine with default configuration
// set landing page and return router variable r
func initGin() *gin.Engine {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": "Welcome to Vizient's Software Wizard Manual"})
})
return r
}