本文整理汇总了Golang中github.com/hashicorp/go-version.NewVersion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewVersion函数的具体用法?Golang NewVersion怎么用?Golang NewVersion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewVersion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
示例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
}
示例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))
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}