-
Notifications
You must be signed in to change notification settings - Fork 32
/
version.go
34 lines (27 loc) · 904 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package api
import (
"context"
"github.com/arigatomachine/cli/apitypes"
)
// VersionClient provides access to the daemon's /v1/version endpoint, for
// inspecting the daemon's release version.
type VersionClient struct {
client *Client
}
// Get returns the daemon's release version.
func (v *VersionClient) Get(ctx context.Context) (*apitypes.Version, error) {
return v.fetchVersion(ctx, false)
}
// GetRegistry returns the registry's release version.
func (v *VersionClient) GetRegistry(ctx context.Context) (*apitypes.Version, error) {
return v.fetchVersion(ctx, true)
}
func (v *VersionClient) fetchVersion(ctx context.Context, proxied bool) (*apitypes.Version, error) {
req, _, err := v.client.NewRequest("GET", "/version", nil, nil, proxied)
if err != nil {
return nil, err
}
version := &apitypes.Version{}
_, err = v.client.Do(ctx, req, version, nil, nil)
return version, err
}