cuelang.org/go@v0.10.1/mod/module/versions.go (about) 1 package module 2 3 import ( 4 "cuelang.org/go/internal/mod/semver" 5 ) 6 7 // Versions implements mvs.Versions[Version]. 8 type Versions struct{} 9 10 // New implements mvs.Versions[Version].Version. 11 func (Versions) Version(v Version) string { 12 return v.Version() 13 } 14 15 // New implements mvs.Versions[Version].Path. 16 func (Versions) Path(v Version) string { 17 return v.Path() 18 } 19 20 // New implements mvs.Versions[Version].New. 21 func (Versions) New(p, v string) (Version, error) { 22 return NewVersion(p, v) 23 } 24 25 // Max implements mvs.Reqs.Max. 26 // 27 // It is consistent with semver.Compare except that as a special case, 28 // the version "" is considered higher than all other versions. The main 29 // module (also known as the target) has no version and must be chosen 30 // over other versions of the same module in the module dependency 31 // graph. 32 // 33 // See [mvs.Reqs] for more detail. 34 func (Versions) Max(v1, v2 string) string { 35 if v1 == "none" || v2 == "" { 36 return v2 37 } 38 if v2 == "none" || v1 == "" { 39 return v1 40 } 41 if semver.Compare(v1, v2) > 0 { 42 return v1 43 } 44 return v2 45 }