-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints.go
38 lines (31 loc) · 962 Bytes
/
endpoints.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
package main
import (
"net/http"
"strings"
"github.com/Masterminds/semver"
"github.com/labstack/echo/v4"
)
func (p *Platform) checkUpdate(ctx echo.Context) error {
c := new(Check)
if err := ctx.Bind(c); err != nil {
return ctx.JSON(http.StatusBadRequest, map[string]string{"message": "bad request", "error": err.Error()})
}
var r Release
p.db.Where("type = ?", strings.ToLower(string(c.Channel))).Last(&r)
latestVersion, err := semver.NewVersion(r.Version)
if err != nil {
return ctx.JSON(http.StatusInternalServerError, map[string]string{"message": "something went wrong"})
}
requestVersion, err := semver.NewVersion(c.Version)
if err != nil {
return ctx.JSON(http.StatusBadRequest, map[string]string{"message": "not a valid version"})
}
checkResp := CheckResponse{
Update: false,
}
if latestVersion.GreaterThan(requestVersion) {
checkResp.Update = true
checkResp.Release = r
}
return ctx.JSON(http.StatusOK, checkResp)
}