You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.0 KiB
51 lines
1.0 KiB
9 months ago
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"pure/model"
|
||
|
"pure/model/response"
|
||
|
"pure/service"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func ParamsMiddleware() gin.HandlerFunc {
|
||
|
return func(c *gin.Context) {
|
||
|
var err error
|
||
|
defer func() {
|
||
|
if err != nil {
|
||
|
c.Abort()
|
||
|
} else {
|
||
|
c.Next()
|
||
|
}
|
||
|
}()
|
||
|
type params struct {
|
||
|
Version string `json:"version"`
|
||
|
}
|
||
|
var p params
|
||
|
if err = c.ShouldBindHeader(&p); err != nil {
|
||
|
response.FailWithMessage("缺少必要参数", c)
|
||
|
return
|
||
|
}
|
||
|
var platform string
|
||
|
tmp := strings.ToUpper(c.Request.UserAgent())
|
||
|
if strings.Contains(tmp, "IPHONE") || strings.Contains(tmp, "IOS") { //
|
||
|
platform = "2"
|
||
|
} else {
|
||
|
platform = "1"
|
||
|
}
|
||
|
c.Set("platform", platform)
|
||
|
if p.Version != "" {
|
||
|
//校验版本号可用性
|
||
|
var version model.VersionV
|
||
|
version, err = service.GetVersion(platform, p.Version)
|
||
|
if err != nil {
|
||
|
response.FailWithMessage("版本号不可取", c)
|
||
|
return
|
||
|
} else {
|
||
|
c.Set("version", version.Version)
|
||
|
c.Set("version_status", version.Status)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|