github.com/bilus/oya@v0.0.3-0.20190301162104-da4acbd394c6/pkg/semver/versions.go (about) 1 package semver 2 3 import ( 4 "sort" 5 6 "github.com/blang/semver" 7 ) 8 9 // Versions represents multiple versions. 10 type Versions []Version 11 12 // Len returns length of version collection 13 func (s Versions) Len() int { 14 return len(s) 15 } 16 17 // Swap swaps two versions inside the collection by its indices 18 func (s Versions) Swap(i, j int) { 19 s[i], s[j] = s[j], s[i] 20 } 21 22 // Less checks if version at index i is less than version at index j 23 func (s Versions) Less(i, j int) bool { 24 return semver.Version(s[i]).LT(semver.Version(s[j])) 25 } 26 27 // Sort sorts a slice of versions 28 func Sort(versions []Version) { 29 sort.Sort(Versions(versions)) 30 }