MCPcopy Index your code
hub / github.com/coder/coder / Validate

Method Validate

apiversion/apiversion.go:49–71  ·  view source on GitHub ↗

Validate validates the given version against the given constraints: A given major.minor version is valid iff: 1. The requested major version is contained within v.supportedMajors 2. If the requested major version is the 'current major', then the requested minor version must be less than or equal to

(version string)

Source from the content-addressed store, hash-verified

47// - 2.0, 2.1, and 2.2 are supported,
48// - 2.3+ is not supported.
49func (v *APIVersion) Validate(version string) error {
50 major, minor, err := Parse(version)
51 if err != nil {
52 return err
53 }
54 if major > v.supportedMajor {
55 return xerrors.Errorf("server is at version %d.%d, behind requested major version %s",
56 v.supportedMajor, v.supportedMinor, version)
57 }
58 if major == v.supportedMajor {
59 if minor > v.supportedMinor {
60 return xerrors.Errorf("server is at version %d.%d, behind requested minor version %s",
61 v.supportedMajor, v.supportedMinor, version)
62 }
63 return nil
64 }
65 for _, mjr := range v.additionalMajors {
66 if major == mjr {
67 return nil
68 }
69 }
70 return xerrors.Errorf("version %s is no longer supported", version)
71}
72
73// Parse parses a valid major.minor version string into (major, minor).
74// Both major and minor must be valid integers separated by a period '.'.

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected