63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package releases
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"oc-publish/occonst"
|
|
)
|
|
|
|
type checkStruct struct {
|
|
Name string `json:"name"`
|
|
Id int `json:"id"`
|
|
}
|
|
|
|
func CheckRelease(version string) (bool, error) {
|
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
|
occonst.PUBLISH_URL,
|
|
occonst.PUBLISH_VERSION,
|
|
version)
|
|
|
|
res, err := http.Get(url)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
body, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
var data checkStruct
|
|
err = json.Unmarshal(body, &data)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return data.Name != "", nil
|
|
}
|
|
|
|
func GetReleaseId(version string) (int, error) {
|
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
|
occonst.PUBLISH_URL,
|
|
occonst.PUBLISH_VERSION,
|
|
version)
|
|
|
|
res, err := http.Get(url)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
body, err := io.ReadAll(res.Body)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
var data checkStruct
|
|
err = json.Unmarshal(body, &data)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return data.Id, nil
|
|
} |