1
0
mirror of https://github.com/IceWhaleTech/CasaOS.git synced 2025-07-03 23:30:39 +02:00
Files
CasaOS/service/casa.go

50 lines
1.0 KiB
Go
Raw Normal View History

2021-09-26 10:35:02 +08:00
package service
import (
json2 "encoding/json"
"time"
2021-09-27 14:17:36 +08:00
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
2021-09-26 10:35:02 +08:00
"github.com/tidwall/gjson"
)
type CasaService interface {
GetCasaosVersion() model.Version
2021-09-26 10:35:02 +08:00
}
type casaService struct{}
2021-09-26 10:35:02 +08:00
/**
* @description: get remote version
* @return {model.Version}
*/
func (o *casaService) GetCasaosVersion() model.Version {
keyName := "casa_version"
var dataStr string
var version model.Version
if result, ok := Cache.Get(keyName); ok {
dataStr, ok = result.(string)
if ok {
data := gjson.Get(dataStr, "data")
json2.Unmarshal([]byte(data.String()), &version)
return version
}
}
2022-02-17 18:43:25 +08:00
v := httper.OasisGet(config.ServerInfo.ServerApi + "/v1/sys/version")
data := gjson.Get(v, "data")
json2.Unmarshal([]byte(data.String()), &version)
2022-02-17 18:43:25 +08:00
if len(version.Version) > 0 {
Cache.Set(keyName, v, time.Minute*20)
}
2022-02-17 18:43:25 +08:00
return version
2022-02-17 18:43:25 +08:00
}
func NewCasaService() CasaService {
return &casaService{}
2021-09-26 10:35:02 +08:00
}