39 lines
897 B
Go
39 lines
897 B
Go
package talos
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type releaseResponse struct {
|
|
TagName string `json:"tag_name"`
|
|
}
|
|
|
|
func LatestVersion() string {
|
|
client := http.Client{Timeout: 10 * time.Second}
|
|
request, err := http.NewRequest(http.MethodGet, "https://api.github.com/repos/siderolabs/talos/releases/latest", nil)
|
|
if err != nil {
|
|
return "v1.13.6"
|
|
}
|
|
request.Header.Set("Accept", "application/vnd.github+json")
|
|
response, err := client.Do(request)
|
|
if err != nil {
|
|
return "v1.13.6"
|
|
}
|
|
defer response.Body.Close()
|
|
if response.StatusCode != http.StatusOK {
|
|
return "v1.13.6"
|
|
}
|
|
var release releaseResponse
|
|
if err := json.NewDecoder(response.Body).Decode(&release); err != nil || release.TagName == "" {
|
|
return "v1.13.6"
|
|
}
|
|
return release.TagName
|
|
}
|
|
|
|
func FactoryHint(version string) string {
|
|
return fmt.Sprintf("https://factory.talos.dev/?version=%s", version)
|
|
}
|