-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.go
More file actions
64 lines (50 loc) · 1.49 KB
/
version.go
File metadata and controls
64 lines (50 loc) · 1.49 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package farp
import "fmt"
// Protocol version constants
const (
// ProtocolVersion is the current FARP protocol version (semver)
ProtocolVersion = "1.3.0"
// ProtocolMajor is the major version
ProtocolMajor = 1
// ProtocolMinor is the minor version
ProtocolMinor = 3
// ProtocolPatch is the patch version
ProtocolPatch = 0
)
// VersionInfo provides version information about the protocol
type VersionInfo struct {
// Version is the full semver string
Version string `json:"version"`
// Major version number
Major int `json:"major"`
// Minor version number
Minor int `json:"minor"`
// Patch version number
Patch int `json:"patch"`
}
// GetVersion returns the current protocol version information
func GetVersion() VersionInfo {
return VersionInfo{
Version: ProtocolVersion,
Major: ProtocolMajor,
Minor: ProtocolMinor,
Patch: ProtocolPatch,
}
}
// IsCompatible checks if a manifest version is compatible with this protocol version
// Compatible means the major version matches and the manifest's minor version
// is less than or equal to the protocol's minor version
func IsCompatible(manifestVersion string) bool {
// Parse manifest version (simple parsing for semver)
var major, minor, patch int
_, err := fmt.Sscanf(manifestVersion, "%d.%d.%d", &major, &minor, &patch)
if err != nil {
return false
}
// Major version must match
if major != ProtocolMajor {
return false
}
// Protocol must support manifest's minor version or higher
return minor <= ProtocolMinor
}