本文整理汇总了Golang中github.com/coreos/go-semver/semver.Version.LessThan方法的典型用法代码示例。如果您正苦于以下问题:Golang Version.LessThan方法的具体用法?Golang Version.LessThan怎么用?Golang Version.LessThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/go-semver/semver.Version
的用法示例。
在下文中一共展示了Version.LessThan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: isCompatibleWithVers
func isCompatibleWithVers(vers map[string]*version.Versions, local types.ID, minV, maxV *semver.Version) bool {
var ok bool
for id, v := range vers {
// ignore comparison with local version
if id == local.String() {
continue
}
if v == nil {
continue
}
clusterv, err := semver.NewVersion(v.Cluster)
if err != nil {
plog.Errorf("cannot understand the cluster version of member %s (%v)", id, err)
continue
}
if clusterv.LessThan(*minV) {
plog.Warningf("the running cluster version(%v) is lower than the minimal cluster version(%v) supported", clusterv.String(), minV.String())
return false
}
if maxV.LessThan(*clusterv) {
plog.Warningf("the running cluster version(%v) is higher than the maximum cluster version(%v) supported", clusterv.String(), maxV.String())
return false
}
ok = true
}
return ok
}
示例2: describe
// describe returns a word describing the process we're about to do ("update", "downgrading", etc)
func describe(a, b semver.Version, verb bool) string {
if verb && a.LessThan(b) {
return "Downgrading"
} else if verb {
return "Upgrading"
} else if a.LessThan(b) {
return "Downgrade"
}
return "Upgrade"
}
示例3: LatestDaemonVersion
// LatestDaemonVersion attempts to retrieve the latest version of fleetd
// that has been registered in the Registry. It returns the version if
// it can be determined (or nil otherwise), and any error encountered.
func (r *EtcdRegistry) LatestDaemonVersion() (*semver.Version, error) {
machs, err := r.Machines()
if err != nil {
if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
err = nil
}
return nil, err
}
var lv *semver.Version
for _, m := range machs {
v, err := semver.NewVersion(m.Version)
if err != nil {
continue
} else if lv == nil || lv.LessThan(*v) {
lv = v
}
}
return lv, nil
}
示例4: capabilityLoop
// capabilityLoop checks the cluster version every 500ms and updates
// the enabledMap when the cluster version increased.
// capabilityLoop MUST be ran in a goroutine before checking capability
// or using capabilityHandler.
func capabilityLoop(s *etcdserver.EtcdServer) {
stopped := s.StopNotify()
var pv *semver.Version
for {
if v := s.ClusterVersion(); v != pv {
if pv == nil || (v != nil && pv.LessThan(*v)) {
pv = v
enableMapMu.Lock()
enabledMap = capabilityMaps[pv.String()]
enableMapMu.Unlock()
plog.Infof("enabled capabilities for version %s", pv)
}
}
select {
case <-stopped:
return
case <-time.After(500 * time.Millisecond):
}
}
}
示例5: isMinImageVersion
// isMinImageVersion will return true if the supplied version is greater then
// or equal to the current CoreOS release indicated by the given release
// channel.
func isMinImageVersion(minVersion semver.Version, release string) (bool, error) {
metaData, err := coreosutil.GetAMIData(release)
if err != nil {
return false, fmt.Errorf("Unable to retrieve current release channel version: %v", err)
}
version, ok := metaData["release_info"]["version"]
if !ok {
return false, fmt.Errorf("Error parsing image metadata for version")
}
current, err := semver.NewVersion(version)
if err != nil {
return false, fmt.Errorf("Error parsing semver from image version %v", err)
}
if minVersion.LessThan(*current) {
return false, nil
}
return true, nil
}
示例6: changeRefs
func changeRefs(data []byte, major *semver.Version) (changed []byte, versions semver.Versions, err error) {
var hlinei, hlinej int // HEAD reference line start/end
var mlinei, mlinej int // master reference line start/end
var vrefhash string
var vrefname string
var vrefv *semver.Version
// Record all available versions, the locations of the master and HEAD lines,
// and details of the best reference satisfying the requested major version.
versions = semver.Versions{}
sdata := string(data)
for i, j := 0, 0; i < len(data); i = j {
size, err := strconv.ParseInt(sdata[i:i+4], 16, 32)
if err != nil {
return nil, nil, fmt.Errorf("cannot parse refs line size: %s", string(data[i:i+4]))
}
if size == 0 {
size = 4
}
j = i + int(size)
if j > len(sdata) {
return nil, nil, fmt.Errorf("incomplete refs data received from GitHub")
}
if sdata[0] == '#' {
continue
}
hashi := i + 4
hashj := strings.IndexByte(sdata[hashi:j], ' ')
if hashj < 0 || hashj != 40 {
continue
}
hashj += hashi
namei := hashj + 1
namej := strings.IndexAny(sdata[namei:j], "\n\x00")
if namej < 0 {
namej = j
} else {
namej += namei
}
name := sdata[namei:namej]
if name == "HEAD" {
hlinei = i
hlinej = j
}
if name == "refs/heads/master" {
mlinei = i
mlinej = j
}
if strings.HasPrefix(name, "refs/tags/v") {
if !strings.HasSuffix(name, "^{}") {
continue // Only accept annotated tags.
}
// Annotated tag is peeled off and overrides the same version just parsed.
name = name[:len(name)-3]
v, err := semver.NewVersion(name[strings.IndexByte(name, 'v')+1:])
if err == nil {
versions = append(versions, v)
if major.Major == v.Major && (vrefv == nil || v == vrefv || vrefv.LessThan(*v)) {
vrefv = v
vrefhash = sdata[hashi:hashj]
vrefname = name
}
}
}
}
// If the file has no HEAD line or the version was not found, report as unavailable.
if hlinei == 0 || vrefhash == "" {
return nil, nil, ErrNoVersion
}
var buf bytes.Buffer
buf.Grow(len(data) + 256)
// Copy the header as-is.
buf.Write(data[:hlinei])
// Extract the original capabilities.
caps := ""
if i := strings.Index(sdata[hlinei:hlinej], "\x00"); i > 0 {
caps = strings.Replace(sdata[hlinei+i+1:hlinej-1], "symref=", "oldref=", -1)
}
// Insert the HEAD reference line with the right hash and a proper symref capability.
var line string
if strings.HasPrefix(vrefname, "refs/heads/") {
if caps == "" {
line = fmt.Sprintf("%s HEAD\x00symref=HEAD:%s\n", vrefhash, vrefname)
} else {
line = fmt.Sprintf("%s HEAD\x00symref=HEAD:%s %s\n", vrefhash, vrefname, caps)
}
} else {
if caps == "" {
line = fmt.Sprintf("%s HEAD\n", vrefhash)
//.........这里部分代码省略.........