CasaOS/service/casa.go

50 lines
1 KiB
Go
Raw Normal View History

2021-09-26 02:35:02 +00:00
package service
import (
json2 "encoding/json"
"time"
2021-09-27 06:17:36 +00:00
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
2021-09-26 02:35:02 +00:00
"github.com/tidwall/gjson"
)
type CasaService interface {
GetCasaosVersion() model.Version
2021-09-26 02:35:02 +00:00
}
type casaService struct{}
2021-09-26 02:35:02 +00: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 10:43:25 +00:00
v := httper.OasisGet(config.ServerInfo.ServerApi + "/v1/sys/version")
data := gjson.Get(v, "data")
json2.Unmarshal([]byte(data.String()), &version)
2022-02-17 10:43:25 +00:00
if len(version.Version) > 0 {
Cache.Set(keyName, v, time.Minute*20)
}
2022-02-17 10:43:25 +00:00
return version
2022-02-17 10:43:25 +00:00
}
func NewCasaService() CasaService {
return &casaService{}
2021-09-26 02:35:02 +00:00
}