mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-25 02:54:42 -05:00
34 lines
702 B
Go
34 lines
702 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"io"
|
||
|
"sub2clash/config"
|
||
|
"sub2clash/model"
|
||
|
)
|
||
|
|
||
|
func CheckUpdate() (bool, string, error) {
|
||
|
get, err := Get("https://api.github.com/repos/nitezs/sub2clash/tags")
|
||
|
if err != nil {
|
||
|
return false, "", errors.New("get version info failed" + err.Error())
|
||
|
|
||
|
}
|
||
|
var version model.Tags
|
||
|
all, err := io.ReadAll(get.Body)
|
||
|
if err != nil {
|
||
|
return false, "", errors.New("get version info failed" + err.Error())
|
||
|
|
||
|
}
|
||
|
err = json.Unmarshal(all, &version)
|
||
|
if err != nil {
|
||
|
return false, "", errors.New("get version info failed" + err.Error())
|
||
|
|
||
|
}
|
||
|
if version[0].Name == config.Version {
|
||
|
return false, "", nil
|
||
|
} else {
|
||
|
return true, version[0].Name, nil
|
||
|
}
|
||
|
}
|