• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang go-version.NewVersion函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: validateRequirements

func validateRequirements(requirements []Requirement, currentVersionMap map[string]ver.Version) error {
	var err error

	for _, requirement := range requirements {
		currentVersion := currentVersionMap[requirement.Tool]

		var minVersionPtr *ver.Version
		if requirement.MinVersion == "" {
			return fmt.Errorf("plugin requirement min version is required")
		}

		minVersionPtr, err = ver.NewVersion(requirement.MinVersion)
		if err != nil {
			return fmt.Errorf("failed to parse plugin required min version (%s) for tool (%s), error: %s", requirement.MinVersion, requirement.Tool, err)
		}

		var maxVersionPtr *ver.Version
		if requirement.MaxVersion != "" {
			maxVersionPtr, err = ver.NewVersion(requirement.MaxVersion)
			if err != nil {
				return fmt.Errorf("failed to parse plugin requirement version (%s) for tool (%s), error: %s", requirement.MaxVersion, requirement.Tool, err)
			}
		}

		if err := validateVersion(currentVersion, *minVersionPtr, maxVersionPtr); err != nil {
			return fmt.Errorf("checking plugin tool (%s) requirements failed, error: %s", requirement.Tool, err)
		}
	}

	return nil
}
开发者ID:godrei,项目名称:bitrise,代码行数:31,代码来源:install.go


示例2: LoadConfigWithDir

func LoadConfigWithDir(reader io.Reader, workingDir string, edwardVersion string, logger common.Logger) (Config, error) {
	config, err := loadConfigContents(reader, workingDir, logger)
	if err != nil {
		return Config{}, errors.WithStack(err)
	}
	if config.MinEdwardVersion != "" && edwardVersion != "" {
		// Check that this config is supported by this version
		minVersion, err1 := version.NewVersion(config.MinEdwardVersion)
		if err1 != nil {
			return Config{}, errors.WithStack(err)
		}
		currentVersion, err2 := version.NewVersion(edwardVersion)
		if err2 != nil {
			return Config{}, errors.WithStack(err)
		}
		if currentVersion.LessThan(minVersion) {
			return Config{}, errors.New("this config requires at least version " + config.MinEdwardVersion)
		}
	}
	err = config.initMaps()

	config.printf("Config loaded with: %d groups and %d services\n", len(config.GroupMap), len(config.ServiceMap))

	return config, errors.WithStack(err)
}
开发者ID:yext,项目名称:edward,代码行数:25,代码来源:config.go


示例3: Validate

func (p *PactFile) Validate() error {
	if p.Provider == nil || p.Provider.Name == "" {
		return errEmptyProvider
	}

	if p.Consumer == nil || p.Consumer.Name == "" {
		return errEmptyConsumer
	}

	psv, err := version.NewVersion(pactSpecificationVersion)
	if err != nil {
		return err
	}

	fpsv, err := version.NewVersion(p.Metadata.PactSpecificationVersion)
	if err != nil {
		return err
	}

	//should be backwards compatible with version 1.0.0
	if fpsv.GreaterThan(psv) {
		return errIncompatiblePact
	}

	return nil
}
开发者ID:SEEK-Jobs,项目名称:pact-go,代码行数:26,代码来源:pact_file.go


示例4: VersionCompare

func VersionCompare(args []string) {
	v0, err := v.NewVersion(args[0])
	if err != nil {
		fatal("Can't parse version string" + err.Error())
	}

	v1, err := v.NewVersion(args[1])
	if err != nil {
		fatal("Can't parse version string" + err.Error())
	}
	fmt.Println(v0.Compare(v1))
}
开发者ID:lalyos,项目名称:cloudbreak-deployer,代码行数:12,代码来源:deployer.go


示例5: CheckVersion

func CheckVersion(v string) error {
	mv, _ := version.NewVersion("2.0.1")
	ov, err := version.NewVersion(v)
	if err != nil {
		return err
	}

	if ov.LessThan(mv) {
		return errors.New(fmt.Sprintf("You are using drafter version %s. Minimum version should be %s", ov, mv))
	}

	return nil
}
开发者ID:dbilovd,项目名称:iglo,代码行数:13,代码来源:parser.go


示例6: validateVersion

// validateVersion checks whether current version is greater or equal to
// supported version.
func validateVersion(supported, current string) bool {
	if supported == "" {
		return true
	}
	vSupported, err := goVersion.NewVersion(supported)
	if err != nil {
		return false
	}
	vCurrent, err := goVersion.NewVersion(current)
	if err != nil {
		return false
	}
	return vCurrent.Compare(vSupported) >= 0
}
开发者ID:tsuru,项目名称:tsuru,代码行数:16,代码来源:cmd.go


示例7: enforceSemver

func enforceSemver(v string) *version.Version {
	semver, err := version.NewVersion(v)
	if err != nil {
		log.Fatalln(err)
	}

	var segments []string
	for i := 0; i < 3; i++ {
		segments = append(segments, strconv.Itoa(semver.Segments()[i]))
	}

	semver, _ = version.NewVersion(strings.Join(segments, "."))

	return semver
}
开发者ID:pivotal-cf,项目名称:rabbitmq-upgrade-preparation,代码行数:15,代码来源:versions.go


示例8: VersionTaggedCommits

// VersionTaggedCommits ...
func VersionTaggedCommits() ([]CommitModel, error) {
	out, err := NewPrintableCommand("git", "tag", "--list").Run()
	if err != nil {
		return []CommitModel{}, err
	}
	taggedCommits := []CommitModel{}
	tags := splitByNewLineAndStrip(out)
	for _, tag := range tags {
		// is tag sem-ver tag?
		_, err := version.NewVersion(tag)
		if err != nil {
			continue
		}

		out, err = NewPrintableCommand("git", "rev-list", "-n", "1", `--pretty=format:commit: %H%ndate: %ct%nauthor: %an%nmessage: %s`, tag).Run()
		if err != nil {
			return []CommitModel{}, err
		}

		commit, err := parseCommit(Strip(out))
		if err != nil {
			return []CommitModel{}, fmt.Errorf("Failed to parse commit: %#v", err)
		}
		commit.Tag = tag

		taggedCommits = append(taggedCommits, commit)
	}

	SortByDate(taggedCommits)

	return taggedCommits, nil
}
开发者ID:bitrise-tools,项目名称:releaseman,代码行数:33,代码来源:git.go


示例9: CheckNewVersion

// CheckNewVersion checks if a new version is available
func CheckNewVersion() {
	if Version == "dev" {
		return
	}
	client := github.NewClient(nil)
	updateURL, err := url.Parse("https://update.traefik.io")
	if err != nil {
		log.Warnf("Error checking new version: %s", err)
		return
	}
	client.BaseURL = updateURL
	releases, resp, err := client.Repositories.ListReleases("containous", "traefik", nil)
	if err != nil {
		log.Warnf("Error checking new version: %s", err)
		return
	}

	if resp.StatusCode != 200 {
		log.Warnf("Error checking new version: status=%s", resp.Status)
		return
	}

	currentVersion, err := goversion.NewVersion(Version)
	if err != nil {
		log.Warnf("Error checking new version: %s", err)
		return
	}

	for _, release := range releases {
		releaseVersion, err := goversion.NewVersion(*release.TagName)
		if err != nil {
			log.Warnf("Error checking new version: %s", err)
			return
		}

		if len(currentVersion.Prerelease()) == 0 && len(releaseVersion.Prerelease()) > 0 {
			continue
		}

		if releaseVersion.GreaterThan(currentVersion) {
			log.Warnf("A new release has been found: %s. Please consider updating.", releaseVersion.String())
			return
		}
	}
}
开发者ID:vdemeester,项目名称:traefik,代码行数:46,代码来源:version.go


示例10: filterVersionTags

func filterVersionTags(tagList []string) []*ver.Version {
	versionTags := []*ver.Version{}
	for _, tag := range tagList {
		versionTag, err := ver.NewVersion(tag)
		if err == nil && versionTag != nil {
			versionTags = append(versionTags, versionTag)
		}
	}
	return versionTags
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:10,代码来源:git.go


示例11: TestParseVersion

func TestParseVersion(t *testing.T) {
	t.Parallel()

	infoBlob := []byte(`{
		"http_config": {
			"https_port": 8443,
			"http_port": 8080,
			"assets_path": null
		},
		"name": "marathon",
		"version": "0.11.1",
		"elected": true,
		"leader": "marathon-leader.example.com:8080",
		"frameworkId": "20150714-191408-4163031306-5050-1590-0000",
		"marathon_config": {
			"mesos_leader_ui_url": "http://marathon-leader.example.com:5050/",
			"leader_proxy_read_timeout_ms": 10000,
			"leader_proxy_connection_timeout_ms": 5000,
			"executor": "//cmd",
			"local_port_max": 20000,
			"local_port_min": 10000,
			"checkpoint": true,
			"ha": true,
			"framework_name": "marathon",
			"failover_timeout": 604800,
			"master": "zk://zk.example.com:2181/mesos",
			"hostname": "marathon-leader.example.com",
			"webui_url": null,
			"mesos_role": null,
			"task_launch_timeout": 300000,
			"reconciliation_initial_delay": 15000,
			"reconciliation_interval": 300000,
			"marathon_store_timeout": 2000,
			"mesos_user": "root"
		},
		"zookeeper_config": {
			"zk_max_versions": 25,
			"zk_session_timeout": 1800000,
			"zk_timeout": 10000,
			"zk": "zk://zk.example.com:2181/marathon"
		},
		"event_subscriber": {
			"http_endpoints": null,
			"type": "http_callback"
		}
  }`)
	m, _ := NewMarathon("localhost:8080", "http", nil)
	v, err := m.ParseVersion(infoBlob)
	assert.Equal(t, v, "0.11.1")
	assert.Nil(t, err)

	// quickly verify that this version can be parsed with the version library
	_, err = version.NewVersion(v)
	assert.Nil(t, err)
}
开发者ID:sadhopedream,项目名称:marathon-consul,代码行数:55,代码来源:marathon_test.go


示例12: newArtifact

func newArtifact(a *nexus.Artifact) (*Artifact, error) {
	v, err := version.NewVersion(a.Version)
	if err != nil {
		return nil, err

	}
	return &Artifact{
		Artifact: a,
		v:        v,
	}, nil
}
开发者ID:gitter-badger,项目名称:alkasir,代码行数:11,代码来源:artifact.go


示例13: testDockerVersion

func (c *Config) testDockerVersion() error {
	endpoint, err := c.GetDockerClient()
	if err != nil {
		return err
	}
	ev, err := endpoint.Version()
	if err != nil {

		return err
	}
	currVersion := ev.Get("ApiVersion")
	activeVersion, err := version.NewVersion(currVersion)
	supportedVersion, err := version.NewVersion(DockerApiVersion)
	if activeVersion.LessThan(supportedVersion) {
		return errors.New(currVersion + " version is lower than supported Docker version of " + DockerApiVersion + ". You will need to upgrade docker.")
	}

	Log.Debug("Found docker API version: ", currVersion)
	c.currentDockerApiVersion = currVersion
	return nil
}
开发者ID:rsk-project,项目名称:codetainer,代码行数:21,代码来源:config.go


示例14: AuditCheck

func (dc *DockerKernelCheck) AuditCheck() (bool, error) {

	cmd := exec.Command("uname", "-r")

	bytes, err := cmd.CombinedOutput()

	if err != nil {
		return false, err
	}

	lines := strings.Split(string(bytes), "\n")

	if len(lines) < 1 {
		return false, errors.New("Nothing returned from uname -r")
	}

	kernelstring := lines[0]
	parts := strings.Split(kernelstring, "-")

	if len(parts) < 1 {
		return false, errors.New("Malformed kernel string" + kernelstring)
	}
	kernelversion := parts[0]

	v1, err := version.NewVersion(kernelversion)
	if err != nil {
		return false, err
	}
	targetVersion, err := version.NewVersion("3.10")
	if err != nil {
		return false, err
	}

	if v1.Compare(targetVersion) >= 0 {
		return true, nil
	}
	// TODO: print out kernel version
	return false, nil
}
开发者ID:jerbia,项目名称:batten,代码行数:39,代码来源:docker_kernel_check.go


示例15: CheckBinaryUpgrade

// CheckBinaryUpgrade returns upgrade meta data if an upgrade is available.
func (c *Client) CheckBinaryUpgrade(request shared.BinaryUpgradeRequest) (shared.BinaryUpgradeResponse, bool, error) {
	data, err := json.Marshal(&request)
	var response shared.BinaryUpgradeResponse
	if err != nil {
		return response, false, err
	}
	resp, err := c.post("upgrades/", bytes.NewBuffer(data))
	if err != nil {
		return response, false, err
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusNotFound {
		return response, false, nil
	}

	if resp.StatusCode != http.StatusOK {
		return response, false,
			fmt.Errorf("Upgradeversion http status response: %d", resp.StatusCode)
	}
	if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
		return response, false, err
	}

	currentVersion, err := version.NewVersion(request.FromVersion)
	if err != nil {
		return response, false, fmt.Errorf("Cannot parse current version from %s", request.FromVersion)
	}
	newVersion, err := version.NewVersion(response.Version)
	if err != nil {
		return response, false, fmt.Errorf("Cannot parse new version from %s", response.Version)
	}
	if currentVersion.GreaterThan(newVersion) {
		return response, false, fmt.Errorf("Received version %s is older than current version %s", newVersion, currentVersion)
	}

	return response, true, nil
}
开发者ID:thomasf,项目名称:alkasir,代码行数:39,代码来源:client.go


示例16: Validate

// Validate ...
func (route PluginRoute) Validate() error {
	if route.Name == "" {
		return fmt.Errorf("invalid route: missing required name")
	}
	if route.Source == "" {
		return fmt.Errorf("invalid route: missing required source")
	}
	if route.Version != "" {
		if _, err := ver.NewVersion(route.Version); err != nil {
			return fmt.Errorf("invalid route: invalid version (%s)", route.Version)
		}
	}
	return nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:15,代码来源:models_methods.go


示例17: Constraint

func Constraint(constraint, version string) bool {
	c, err := semver.NewConstraint(constraint)
	if err != nil {
		idl.Err(err)
		return false
	}

	v, err := semver.NewVersion(version)
	if err != nil {
		idl.Debug(err)
		return false
	}

	return c.Check(v)
}
开发者ID:ionDynamics,项目名称:siteMgr,代码行数:15,代码来源:siteMgr.go


示例18: GitCloneAndCheckoutVersion

// GitCloneAndCheckoutVersion ...
func GitCloneAndCheckoutVersion(cloneIntoDir, repositoryURL, checkoutVersion string) (*ver.Version, string, error) {
	if err := gitInitWithRemote(cloneIntoDir, repositoryURL); err != nil {
		return nil, "", err
	}

	var version ver.Version

	if checkoutVersion == "" {
		versionTagList, err := GitVersionTags(cloneIntoDir)
		if err != nil {
			return nil, "", fmt.Errorf("Could not get version tag list, error: %s", err)
		}

		if len(versionTagList) == 0 {
			return nil, "", fmt.Errorf("no version tag found")
		}

		versionPtr := versionTagList[len(versionTagList)-1]
		if versionPtr == nil {
			return nil, "", fmt.Errorf("uninitialized version found")
		}

		version = *versionPtr
	} else {
		versionPtr, err := ver.NewVersion(checkoutVersion)
		if err != nil {
			return nil, "", fmt.Errorf("failed to parse version (%s), error: %s", checkoutVersion, err)
		}

		if versionPtr == nil {
			return nil, "", errors.New("failed to parse version (%s), error: nil version")
		}

		version = *versionPtr
	}

	if err := gitCheckout(cloneIntoDir, version.String()); err != nil {
		return nil, "", fmt.Errorf("Could not checkout, err :%s", err)
	}

	hash, err := commitHashOfTag(cloneIntoDir, version.String())
	if err != nil {
		return nil, "", fmt.Errorf("Could get commit hash of tag (%s), err :%s", version.String(), err)
	}

	return &version, hash, nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:48,代码来源:git.go


示例19: CheckDockerVersion

func CheckDockerVersion(t Target) (res Result) {
	res.Name = "1.5 Keep Docker up to date"
	verConstr := os.Getenv("VERSION")
	info, err := t.Client.ServerVersion()
	if err != nil {
		log.Fatalf("Could not retrieve info for Docker host")
	}
	constraints, _ := version.NewConstraint(">= " + verConstr)
	hostVersion, _ := version.NewVersion(info.Version)
	if constraints.Check(hostVersion) {
		res.Pass()
	} else {
		output := fmt.Sprintf("Host is using an outdated Docker server: %s ",
			info.Version)
		res.Fail(output)
	}
	return
}
开发者ID:diogomonica,项目名称:actuary,代码行数:18,代码来源:dockerhost.go


示例20: isOsVersionGreater

// Compares sematic versions with 2 components (9.1, 9.2, ...)
// Return true if first version is greater then second
func isOsVersionGreater(osVersion, otherOsVersion string) (bool, error) {
	versionPtrs := []*ver.Version{}
	for _, osVer := range []string{osVersion, otherOsVersion} {
		osVersionSplit := strings.Split(osVer, " ")
		if len(osVersionSplit) != 2 {
			return false, fmt.Errorf("failed to parse version: %s", osVer)
		}

		version, err := ver.NewVersion(osVersionSplit[1])
		if err != nil {
			return false, err
		}

		versionPtrs = append(versionPtrs, version)
	}

	return versionPtrs[0].GreaterThan(versionPtrs[1]), nil
}
开发者ID:bitrise-io,项目名称:steps-xcode-test,代码行数:20,代码来源:xcodeutil.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang golang-lru.New函数代码示例发布时间:2022-05-23
下一篇:
Golang go-multierror.Error类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap