-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.go
35 lines (33 loc) · 944 Bytes
/
meta.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
35
package wharfapi
import (
"github.com/blang/semver/v4"
"github.com/iver-wharf/wharf-core/pkg/app"
)
// GetVersion gets the version of the API by invoking the
// HTTP request:
// GET /api/version
//
// Added in wharf-api v4.0.0.
func (c *Client) GetVersion() (app.Version, error) {
if err := c.validateEndpointVersionNoLookup(4, 0, 0, c.cachedVersion); err != nil {
return app.Version{}, err
}
var version app.Version
err := c.getUnmarshal("/api/version", nil, &version)
if err != nil {
return app.Version{}, err
}
hadCheckedVersion := c.hasCheckedVersion
c.hasCheckedVersion = true
v, err := semver.ParseTolerant(version.Version)
if err != nil {
if !hadCheckedVersion {
log.Warn().WithError(err).
WithString("version", version.Version).
Message("Failed to parse version from API. Version validation is turned off. Use at your own risk.")
}
return version, nil
}
c.cachedVersion = &v
return version, nil
}