mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
780d942fad
closes: https://github.com/hasura/graphql-engine/issues/4926 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3307 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 90222fc2e5b176fbf5721fea3f5b2af929ca93f4
36 lines
900 B
Go
36 lines
900 B
Go
package version
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
|
|
)
|
|
|
|
type serverVersionResponse struct {
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// FetchServerVersion reads the version from server.
|
|
func FetchServerVersion(endpoint string, client *httpc.Client) (version string, err error) {
|
|
req, err := http.NewRequest("GET", endpoint, nil)
|
|
if err != nil {
|
|
return "", fmt.Errorf("error while making http request to %s", endpoint)
|
|
}
|
|
var v serverVersionResponse
|
|
response, err := client.Do(context.Background(), req, &v)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed making version api call: %w", err)
|
|
}
|
|
if response.StatusCode != http.StatusOK {
|
|
switch response.StatusCode {
|
|
case http.StatusNotFound:
|
|
return "", nil
|
|
default:
|
|
return "", fmt.Errorf("GET %s failed - [%d]", endpoint, response.StatusCode)
|
|
}
|
|
}
|
|
return v.Version, nil
|
|
}
|