当前位置: 首页>>代码示例>>Golang>>正文


Golang semver.NewVersion函数代码示例

本文整理汇总了Golang中github.com/Masterminds/semver.NewVersion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVersion函数的具体用法?Golang NewVersion怎么用?Golang NewVersion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewVersion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CheckLatest

// CheckLatest checks whether this version of Helm is the latest version.
//
// This does not ensure that this is the latest. If a newer version is found,
// this generates a message indicating that.
//
// The passed-in version is the base version that will be checked against the
// remote release list.
func CheckLatest(version string) {
	ver, err := release.LatestVersion()
	if err != nil {
		log.Warn("Skipped Helm version check: %s", err)
		return
	}

	current, err := semver.NewVersion(version)
	if err != nil {
		log.Warn("Local version %s is not well-formed", version)
		return
	}
	remote, err := semver.NewVersion(ver)
	if err != nil {
		log.Warn("Remote version %s is not well-formed", ver)
		return
	}

	if remote.GreaterThan(current) {
		log.Warn("A new version of Helm is available. You have %s. The latest is %v", version, ver)
		if dl, err := release.LatestDownloadURL(); err == nil {
			log.Info("Download version %s here: %s", ver, dl)
		}
	}

}
开发者ID:prydonius,项目名称:helm-classic,代码行数:33,代码来源:update.go

示例2: put

func (m *memCache) put(name, version string) {
	m.Lock()
	defer m.Unlock()
	m.t[name] = true
	sv, err := semver.NewVersion(version)
	if err != nil {
		msg.Debug("Ignoring %s version %s: %s", name, version, err)
		return
	}

	latest, found := m.latest[name]
	if found {
		lv, err := semver.NewVersion(latest)
		if err == nil {
			if sv.GreaterThan(lv) {
				m.latest[name] = version
			}
		}
	} else {
		m.latest[name] = version
	}

	found = false
	for _, v := range m.versions[name] {
		if v == version {
			found = true
		}
	}
	if !found {
		m.versions[name] = append(m.versions[name], version)
	}
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:32,代码来源:memory.go

示例3: versionEquals

func versionEquals(v1, v2 string) bool {
	sv1, err := semver.NewVersion(v1)
	if err != nil {
		// Fallback to string comparison.
		return v1 == v2
	}
	sv2, err := semver.NewVersion(v2)
	if err != nil {
		return false
	}
	return sv1.Equal(sv2)
}
开发者ID:kubernetes,项目名称:helm,代码行数:12,代码来源:manager.go

示例4: Less

// Less returns true if the version of entry a is less than the version of entry b.
func (c ChartVersions) Less(a, b int) bool {
	// Failed parse pushes to the back.
	i, err := semver.NewVersion(c[a].Version)
	if err != nil {
		return true
	}
	j, err := semver.NewVersion(c[b].Version)
	if err != nil {
		return false
	}
	return i.LessThan(j)
}
开发者ID:slack,项目名称:helm,代码行数:13,代码来源:index.go

示例5: getWizard

func getWizard(dep *cfg.Dependency) {
	var remote string
	if dep.Repository != "" {
		remote = dep.Repository
	} else {
		remote = "https://" + dep.Name
	}

	// Lookup dependency info and store in cache.
	msg.Info("--> Gathering release information for %s", dep.Name)
	wizardFindVersions(dep)

	memlatest := cache.MemLatest(remote)
	if memlatest != "" {
		dres := wizardAskLatest(memlatest, dep)
		if dres {
			dep.Reference = memlatest

			sv, err := semver.NewVersion(dep.Reference)
			if err == nil {
				res := wizardAskRange(sv, dep)
				if res == "m" {
					dep.Reference = "^" + sv.String()
				} else if res == "p" {
					dep.Reference = "~" + sv.String()
				}
			}
		}
	}
}
开发者ID:treejames,项目名称:glide-1,代码行数:30,代码来源:get.go

示例6: Resolve

// Resolve resolves dependencies and returns a lock file with the resolution.
func (r *Resolver) Resolve(reqs *chartutil.Requirements) (*chartutil.RequirementsLock, error) {
	d, err := HashReq(reqs)
	if err != nil {
		return nil, err
	}

	// Now we clone the dependencies, locking as we go.
	locked := make([]*chartutil.Dependency, len(reqs.Dependencies))
	for i, d := range reqs.Dependencies {
		// Right now, we're just copying one entry to another. What we need to
		// do here is parse the requirement as a SemVer range, and then look up
		// whether a version in index.yaml satisfies this constraint. If so,
		// we need to clone the dep, setting Version appropriately.
		// If not, we need to error out.
		if _, err := semver.NewVersion(d.Version); err != nil {
			return nil, fmt.Errorf("dependency %q has an invalid version: %s", d.Name, err)
		}
		locked[i] = &chartutil.Dependency{
			Name:       d.Name,
			Repository: d.Repository,
			Version:    d.Version,
		}
	}

	return &chartutil.RequirementsLock{
		Generated:    time.Now(),
		Digest:       d,
		Dependencies: locked,
	}, nil
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:31,代码来源:resolver.go

示例7: benchCheckVersion

func benchCheckVersion(c, v string, b *testing.B) {
	version, _ := semver.NewVersion(v)
	constraint, _ := semver.NewConstraint(c)

	for i := 0; i < b.N; i++ {
		constraint.Check(version)
	}
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:8,代码来源:benchmark_test.go

示例8: benchValidateVersion

func benchValidateVersion(c, v string, b *testing.B) {
	version, _ := semver.NewVersion(v)
	constraint, _ := semver.NewConstraint(c)

	for i := 0; i < b.N; i++ {
		constraint.Validate(version)
	}
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:8,代码来源:benchmark_test.go

示例9: setCurrent

func (m *memCache) setCurrent(name, version string) {
	m.Lock()
	defer m.Unlock()

	if m.c[name] == "" {
		m.c[name] = version
	} else {
		// If we already have a version try to see if the new or old one is
		// semver and use that one.
		_, err := semver.NewVersion(m.c[name])
		if err != nil {
			_, err2 := semver.NewVersion(version)
			if err2 == nil {
				m.c[name] = version
			}
		}
	}
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:18,代码来源:memory.go

示例10: Resolve

// Resolve resolves dependencies and returns a lock file with the resolution.
func (r *Resolver) Resolve(reqs *chartutil.Requirements, repoNames map[string]string) (*chartutil.RequirementsLock, error) {
	d, err := HashReq(reqs)
	if err != nil {
		return nil, err
	}

	// Now we clone the dependencies, locking as we go.
	locked := make([]*chartutil.Dependency, len(reqs.Dependencies))
	missing := []string{}
	for i, d := range reqs.Dependencies {
		constraint, err := semver.NewConstraint(d.Version)
		if err != nil {
			return nil, fmt.Errorf("dependency %q has an invalid version/constraint format: %s", d.Name, err)
		}

		repoIndex, err := repo.LoadIndexFile(r.helmhome.CacheIndex(repoNames[d.Name]))
		if err != nil {
			return nil, fmt.Errorf("no cached repo found. (try 'helm repo update'). %s", err)
		}

		vs, ok := repoIndex.Entries[d.Name]
		if !ok {
			return nil, fmt.Errorf("%s chart not found in repo %s", d.Name, d.Repository)
		}

		locked[i] = &chartutil.Dependency{
			Name:       d.Name,
			Repository: d.Repository,
		}
		found := false
		// The version are already sorted and hence the first one to satisfy the constraint is used
		for _, ver := range vs {
			v, err := semver.NewVersion(ver.Version)
			if err != nil || len(ver.URLs) == 0 {
				// Not a legit entry.
				continue
			}
			if constraint.Check(v) {
				found = true
				locked[i].Version = v.Original()
				break
			}
		}

		if !found {
			missing = append(missing, d.Name)
		}
	}
	if len(missing) > 0 {
		return nil, fmt.Errorf("Can't get a valid version for repositories %s. Try changing the version constraint in requirements.yaml", strings.Join(missing, ", "))
	}
	return &chartutil.RequirementsLock{
		Generated:    time.Now(),
		Digest:       d,
		Dependencies: locked,
	}, nil
}
开发者ID:kubernetes,项目名称:helm,代码行数:58,代码来源:resolver.go

示例11: getSemVers

// Filter a list of versions to only included semantic versions. The response
// is a mapping of the original version to the semantic version.
func getSemVers(refs []string) []*semver.Version {
	sv := []*semver.Version{}
	for _, r := range refs {
		v, err := semver.NewVersion(r)
		if err == nil {
			sv = append(sv, v)
		}
	}

	return sv
}
开发者ID:rudle,项目名称:glide,代码行数:13,代码来源:semver.go

示例12: VersionOK

// VersionOK returns true if the given version meets the constraints.
//
// It returns false if the version string or constraint is unparsable or if the
// version does not meet the constraint.
func (d *Dependency) VersionOK(version string) bool {
	c, err := semver.NewConstraint(d.Version)
	if err != nil {
		return false
	}
	v, err := semver.NewVersion(version)
	if err != nil {
		return false
	}

	return c.Check(v)
}
开发者ID:huhoo,项目名称:deployment-manager,代码行数:16,代码来源:chartfile.go

示例13: Less

// Less compares a to b, and returns true if a is less than b.
func (s scoreSorter) Less(a, b int) bool {
	first := s[a]
	second := s[b]

	if first.Score > second.Score {
		return false
	}
	if first.Score < second.Score {
		return true
	}
	if first.Name == second.Name {
		v1, err := semver.NewVersion(first.Chart.Version)
		if err != nil {
			return true
		}
		v2, err := semver.NewVersion(second.Chart.Version)
		if err != nil {
			return true
		}
		return v1.GreaterThan(v2)
	}
	return first.Name < second.Name
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:24,代码来源:search.go

示例14: CheckLatest

// CheckLatest checks whether this version of Helm Classic is the latest version.
//
// This does not ensure that this is the latest. If a newer version is found,
// this generates a message indicating that.
//
// The passed-in version is the base version that will be checked against the
// remote release list.
func CheckLatest(version string) {
	ver, err := release.LatestVersion()
	if err != nil {
		log.Warn("Skipped Helm Classic version check: %s", err)
		return
	}

	current, err := semver.NewVersion(version)
	if err != nil {
		log.Warn("Local version %s is not well-formed", version)
		return
	}
	remote, err := semver.NewVersion(ver)
	if err != nil {
		log.Warn("Remote version %s is not well-formed", ver)
		return
	}

	if remote.GreaterThan(current) {
		log.Warn("A new version of Helm Classic is available. You have %s. The latest is %v", version, ver)
		log.Info("Download version %s by running: %s", ver, "curl -s https://get.helm.sh | bash")
	}

}
开发者ID:helm,项目名称:helm-classic,代码行数:31,代码来源:update.go

示例15: getSemverTags

func getSemverTags() []*semver.Version {
	rowTags := git("tag")

	tags := bytes.Split(rowTags, []byte("\n"))
	tags = tags[:len(tags)-1]

	vs := make([]*semver.Version, 0)

	for _, r := range tags {
		v, err := semver.NewVersion(string(r))
		if err == nil {
			vs = append(vs, v)
		}
	}

	sort.Sort(sort.Reverse(semver.Collection(vs)))
	return vs
}
开发者ID:kron4eg,项目名称:git-changelog,代码行数:18,代码来源:cmd.go


注:本文中的github.com/Masterminds/semver.NewVersion函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。