github.com/supabase/cli@v1.168.1/internal/utils/tenant/gotrue.go (about)

     1  package tenant
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/go-errors/errors"
     8  	"github.com/supabase/cli/pkg/fetcher"
     9  )
    10  
    11  var errGotrueVersion = errors.New("GoTrue version not found.")
    12  
    13  type HealthResponse struct {
    14  	Version     string `json:"version"`
    15  	Name        string `json:"name"`
    16  	Description string `json:"description"`
    17  }
    18  
    19  func (t *TenantAPI) GetGotrueVersion(ctx context.Context) (string, error) {
    20  	resp, err := t.Send(ctx, http.MethodGet, "/auth/v1/health", nil)
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  	defer resp.Body.Close()
    25  	data, err := fetcher.ParseJSON[HealthResponse](resp.Body)
    26  	if err != nil {
    27  		return "", err
    28  	}
    29  	if len(data.Version) == 0 {
    30  		return "", errors.New(errGotrueVersion)
    31  	}
    32  	return data.Version, nil
    33  }