package utils import ( "bytes" "encoding/json" "fmt" "io" "net/http" ) func CheckZipExist(url string) (bool, error) { res, err := http.Get(url) if err != nil { return false, err } defer res.Body.Close() buf := make([]byte, 1024) n, err := res.Body.Read(buf) if err != nil { return false, err } if n != 1024 { return true, nil } return false, nil } // 返回succ,fail func PostJson(data []byte) (string, error) { req, err := http.NewRequest("POST", VersionApi, bytes.NewBuffer(data)) if err != nil { return "fail", err } req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { return "fail", err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return "fail", err } return string(body), nil } func GetAppVersion(query string) (*AppVersion, error) { url := fmt.Sprintf("%s%s", VersionApi, query) client := &http.Client{} resp, err := client.Get(url) if err != nil { return nil, err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } appVersion := &AppVersion{} err = json.Unmarshal(body, appVersion) if err != nil { return nil, err } return appVersion, nil }