repo_description: 🧊 The next generation Package Manager for Kubernetes 📦 Featuring a GUI and a CLI. Glasskube packages are dependency aware, GitOps ready and can get automatic updates via a central public package repository.
repo_topics: cloud-native cncf cobra cobra-cli containers devops devops-tools docusaurus giscuss glasskube go golang htmx kubebuilder kubernetes kubernetes-operator package package-manager
code: package releaseinfo
  
  import (
  	"encoding/json"
  	"net/http"
  	"sync"
  
  	"github.com/glasskube/glasskube/internal/httperror"
  )
  
  type ReleaseInfo struct {
  	Version string `json:"version"`
  }
  
  var cachedResponse *ReleaseInfo
  var mutex sync.Mutex
  
  func FetchLatestRelease() (*ReleaseInfo, error) {
  	mutex.Lock()
  	defer mutex.Unlock()
  
  	if cachedResponse == nil {
  		resp, err := httperror.CheckResponse(http.Get("https://glasskube.dev/release.json"))
  		if err != nil {
  			return nil, err
  		}
  		defer func() {
  			_ = resp.Body.Close()
  		}()
  
  		var releaseInfo ReleaseInfo
  		if err := json.NewDecoder(resp.Body).Decode(&releaseInfo); err != nil {
  			return nil, err
  		}
  
  		cachedResponse = &releaseInfo
  	}
  
  	return &ReleaseInfo{cachedResponse.Version}, nil
  }
  