-
Notifications
You must be signed in to change notification settings - Fork 1
/
Routes.go
55 lines (49 loc) · 1.47 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
package http
import (
"github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"github.com/kerberos-io/glass/api/src/components"
"github.com/kerberos-io/glass/api/src/models"
)
func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterGroup{
api := r.Group("/api")
{
api.POST("/login", authMiddleware.LoginHandler)
api.GET("/install", GetInstallation)
api.POST("/install", UpdateInstallation)
api.Use(authMiddleware.MiddlewareFunc())
{
// Secured endpoints..
}
}
return api
}
// GetInstallation example
// @Summary Get to know if the system was installed before or not.
// @Description Get to know if the system was installed before or not.
// @ID web.getinstallation
// @Produce json
// @Success 200 {object} models.APIResponse
// @Router /api/install [get]
func GetInstallation(c *gin.Context) {
// Get the user configuration
userConfig := components.ReadUserConfig()
c.JSON(200, models.APIResponse{
Data: userConfig.Installed,
})
}
// UpdateInstallation example
// @Summary If not yet installed, initiate the user configuration.
// @Description If not yet installed, initiate the user configuration.
// @ID web.updateinstallation
// @Produce json
// @Success 200 {object} models.APIResponse
// @Router /api/install [post]
func UpdateInstallation(c *gin.Context) {
// TODO update user config and update global object.
// userConfig = ...
userConfig := components.ReadUserConfig()
c.JSON(200, models.APIResponse{
Data: userConfig,
})
}