-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversioning.go
35 lines (28 loc) · 973 Bytes
/
versioning.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 db
import "encoding/json"
// Version is the type for library versions.
type Version struct {
version string
}
// Less returns whether the receiver version is lower than the argument.
func (version *Version) Less(other Version) (bool, error) {
// TODO: apply semantic versioning
return version.version < other.version, nil
}
// String returns the version in string form.
func (version *Version) String() string {
return version.version
}
// UnmarshalJSON parses the JSON-encoded argument and stores the result in the receiver.
func (version *Version) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &version.version)
}
// MarshalJSON returns the JSON encoding of the receiver.
func (version *Version) MarshalJSON() ([]byte, error) {
// Encode version as a string
return json.Marshal(version.version)
}
// VersionFromString parses a string to a Version object.
func VersionFromString(str string) Version {
return Version{version: str}
}