當前位置: 首頁>>代碼示例>>Golang>>正文


Golang semver.MustParse函數代碼示例

本文整理匯總了Golang中github.com/blang/semver.MustParse函數的典型用法代碼示例。如果您正苦於以下問題:Golang MustParse函數的具體用法?Golang MustParse怎麽用?Golang MustParse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MustParse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestComponentGetters

func TestComponentGetters(t *testing.T) {
	testSatisfies := []Satisfies{{Narrative: "Narrative"}, {}, {}, {}}
	component := Component{
		Name:          "Amazon Elastic Compute Cloud",
		Key:           "EC2",
		References:    common.GeneralReferences{{}},
		Verifications: common.VerificationReferences{{}, {}},
		Satisfies:     testSatisfies,
		SchemaVersion: semver.MustParse("2.0.0"),
	}
	// Test the getters
	assert.Equal(t, "EC2", component.GetKey())
	assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
	assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
	assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
	assert.Equal(t, semver.MustParse("2.0.0"), component.GetVersion())
	assert.Equal(t, "", component.GetResponsibleRole())
	assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
	for idx, satisfies := range component.GetAllSatisfies() {
		assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
		assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
		assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
		for i, narrative := range satisfies.GetNarratives() {
			assert.Equal(t, "", narrative.GetKey())
			assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
		}
		assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
		assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
		assert.Equal(t, "", satisfies.GetControlOrigin())
	}
}
開發者ID:geramirez,項目名稱:compliance-masonry,代碼行數:31,代碼來源:component_test.go

示例2: ensureThinLsKernelVersion

func ensureThinLsKernelVersion(kernelVersion string) error {
	// kernel 4.4.0 has the proper bug fixes to allow thin_ls to work without corrupting the thin pool
	minKernelVersion := semver.MustParse("4.4.0")
	// RHEL 7 kernel 3.10.0 release >= 366 has the proper bug fixes backported from 4.4.0 to allow
	// thin_ls to work without corrupting the thin pool
	minRhel7KernelVersion := semver.MustParse("3.10.0")

	matches := version_re.FindStringSubmatch(kernelVersion)
	if len(matches) < 4 {
		return fmt.Errorf("error parsing kernel version: %q is not a semver", kernelVersion)
	}

	sem, err := semver.Make(matches[0])
	if err != nil {
		return err
	}

	if sem.GTE(minKernelVersion) {
		// kernel 4.4+ - good
		return nil
	}

	// Certain RHEL/Centos 7.x kernels have a backport to fix the corruption bug
	if !strings.Contains(kernelVersion, ".el7") {
		// not a RHEL 7.x kernel - won't work
		return fmt.Errorf("kernel version 4.4.0 or later is required to use thin_ls - you have %q", kernelVersion)
	}

	// RHEL/Centos 7.x from here on
	if sem.Major != 3 {
		// only 3.x kernels *may* work correctly
		return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
	}

	if sem.GT(minRhel7KernelVersion) {
		// 3.10.1+ - good
		return nil
	}

	if sem.EQ(minRhel7KernelVersion) {
		// need to check release
		releaseRE := regexp.MustCompile(`^[^-]+-([0-9]+)\.`)
		releaseMatches := releaseRE.FindStringSubmatch(kernelVersion)
		if len(releaseMatches) != 2 {
			return fmt.Errorf("unable to determine RHEL/Centos 7.x kernel release from %q", kernelVersion)
		}

		release, err := strconv.Atoi(releaseMatches[1])
		if err != nil {
			return fmt.Errorf("error parsing release %q: %v", releaseMatches[1], err)
		}

		if release >= 366 {
			return nil
		}
	}

	return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
}
開發者ID:jbeda,項目名稱:kubernetes,代碼行數:59,代碼來源:factory.go

示例3: TestComponentSetters

func TestComponentSetters(t *testing.T) {
	component := Component{}
	// Test the setters.
	// Change the version.
	component.SetVersion(semver.MustParse("3.0.0"))
	assert.Equal(t, semver.MustParse("3.0.0"), component.GetVersion())
	// Change the key.
	component.SetKey("FooKey")
	assert.Equal(t, "FooKey", component.GetKey())
}
開發者ID:geramirez,項目名稱:compliance-masonry,代碼行數:10,代碼來源:component_test.go

示例4: TestComponentGetters

func TestComponentGetters(t *testing.T) {
	testSatisfies := []Satisfies{
		{
			ControlOrigin:          "inherited",
			ControlOrigins:         []string{"inherited"},
			ImplementationStatus:   "partial",
			ImplementationStatuses: []string{"partial"},
			Parameters:             []Section{Section{Key: "key", Text: "text"}},
			Narrative: []NarrativeSection{
				NarrativeSection{Key: "key", Text: "text"},
				NarrativeSection{Text: "text"},
			},
		}, {}}
	component := Component{
		Name:            "Amazon Elastic Compute Cloud",
		Key:             "EC2",
		ResponsibleRole: "AWS Staff",
		References:      common.GeneralReferences{{}},
		Verifications:   common.VerificationReferences{{}, {}},
		Satisfies:       testSatisfies,
		SchemaVersion:   semver.MustParse("3.1.0"),
	}
	// Test the getters
	assert.Equal(t, "EC2", component.GetKey())
	assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
	assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
	assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
	assert.Equal(t, semver.MustParse("3.1.0"), component.GetVersion())
	assert.Equal(t, "AWS Staff", component.GetResponsibleRole())
	assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
	for idx, satisfies := range component.GetAllSatisfies() {
		assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
		assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
		assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
		for i, narrative := range satisfies.GetNarratives() {
			assert.Equal(t, satisfies.GetNarratives()[i].GetKey(), narrative.GetKey())
			assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
		}
		assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
		for i, parameter := range satisfies.GetParameters() {
			assert.Equal(t, satisfies.GetParameters()[i].GetKey(), parameter.GetKey())
			assert.Equal(t, satisfies.GetParameters()[i].GetText(), parameter.GetText())
		}
		assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
		assert.Equal(t, satisfies.GetControlOrigin(), testSatisfies[idx].GetControlOrigin())
		assert.Equal(t, satisfies.GetControlOrigins(), testSatisfies[idx].GetControlOrigins())
		assert.Equal(t, satisfies.GetImplementationStatus(), testSatisfies[idx].GetImplementationStatus())
		assert.Equal(t, satisfies.GetImplementationStatuses(), testSatisfies[idx].GetImplementationStatuses())
	}
}
開發者ID:opencontrol,項目名稱:compliance-masonry,代碼行數:50,代碼來源:component_test.go

示例5: checkVersion

func checkVersion() {
	server := new(Version)
	mustGetObject("/version", nil, server)
	grindCurrent := semver.MustParse(CurrentVersion.Version)
	grindRequired := semver.MustParse(server.GrindVersionRequired)
	if grindRequired.GT(grindCurrent) {
		log.Printf("this is grind version %s, but the server requires %s or higher", CurrentVersion.Version, server.GrindVersionRequired)
		log.Fatalf("  you must upgrade to continue")
	}
	grindRecommended := semver.MustParse(server.GrindVersionRecommended)
	if grindRecommended.GT(grindCurrent) {
		log.Printf("this is grind version %s, but the server recommends %s or higher", CurrentVersion.Version, server.GrindVersionRecommended)
		log.Printf("  please upgrade as soon as possible")
	}
}
開發者ID:RidleyLarsen,項目名稱:codegrinder,代碼行數:15,代碼來源:main.go

示例6: use

func use(version dockerversion.Version) {
	writeDebug("dvm use %s", version)

	if version.IsEmpty() {
		die("The use command requires that a version is specified or the DOCKER_VERSION environment variable is set.", nil, retCodeInvalidOperation)
	}

	if version.HasAlias() && aliasExists(version.Alias) {
		aliasedVersion, _ := ioutil.ReadFile(getAliasPath(version.Alias))
		version.SemVer = semver.MustParse(string(aliasedVersion))
		writeDebug("Using alias: %s -> %s", version.Alias, version.SemVer)
	}

	ensureVersionIsInstalled(version)

	if version.IsSystem() {
		version, _ = getSystemDockerVersion()
	} else if version.IsExperimental() {
		version, _ = getExperimentalDockerVersion()
	}

	removePreviousDockerVersionFromPath()
	if !version.IsSystem() {
		prependDockerVersionToPath(version)
	}

	writePathScript()
	writeInfo("Now using Docker %s", version)
}
開發者ID:getcarina,項目名稱:dvm,代碼行數:29,代碼來源:dvm-helper.go

示例7: TestUnmarshal

func TestUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	jsonData := []byte(`{
        "version": "0.0.1",
        "path": "./test_artifacts"
    }`)

	cfg := config.NewConfig(version)

	err = json.Unmarshal(jsonData, &cfg)
	w.BailIfErrorf(err, "deserializazion failed: %v", err)

	provider, err := FromConfig(cfg)
	w.BailIfErrorf(err, "instantiation failed: %v", err)

	root, err := provider.Root()
	w.BailIfError(err)

	_, err = checkDirectoryContents(root, expectedRootEntries())

	w.BailIfErrorf(err, "provider path differs")
}
開發者ID:DirtyHairy,項目名稱:csync,代碼行數:26,代碼來源:marshalling_test.go

示例8: getLatestVersion

func getLatestVersion(zipFile []byte, prefix, suffix string) (string, error) {
	r, err := zip.NewReader(bytes.NewReader(zipFile), int64(len(zipFile)))
	if err != nil {
		return "", err
	}
	latest := ""
	for _, f := range r.File {
		artifact := path.Base(f.Name)
		if strings.HasPrefix(artifact, prefix) && strings.HasSuffix(artifact, suffix) {
			v := extractVersion(artifact)
			if latest == "" {
				latest = v
			}
			v1, err := semver.Parse(v)
			if err != nil {
				return "", err
			}
			l := semver.MustParse(latest)
			if v1.GT(l) {
				latest = v
			}
		}
	}
	return latest, nil
}
開發者ID:fikridroid,項目名稱:gradleplease,代碼行數:25,代碼來源:get_versions.go

示例9: getReleases

func getReleases() ([]semver.Version, map[string]Version, error) {
	res, err := http.Get("https://api.github.com/repos/nlf/dhyve-os/releases")
	if err != nil {
		return nil, nil, err
	}

	defer res.Body.Close()
	vers := []Version{}
	decoder := json.NewDecoder(res.Body)
	err = decoder.Decode(vers)
	if err != nil {
		return nil, nil, err
	}

	versions := map[string]Version{}
	rng, err := semver.ParseRange(">= 3.0.0-beta0")
	if err != nil {
		return nil, nil, err
	}

	svers := []semver.Version{}
	for _, vers := range versions {
		v := semver.MustParse(vers.Tag)
		if rng(v) {
			versions[vers.Tag] = vers
			svers = append(svers, v)
		}
	}

	semver.Sort(svers)
	return svers, versions, nil
}
開發者ID:carriercomm,項目名稱:dlite,代碼行數:32,代碼來源:os.go

示例10: TestMarshalUnmarshal

func TestMarshalUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	provider, err := local.NewLocalFS("./test_artifacts")

	w.BailIfError(err)

	cfg := provider.Marshal()
	jsonData, err := json.Marshal(cfg)

	w.BailIfErrorf(err, "serialization failed: %v", err)

	if !strings.Contains(string(jsonData), "test_artifacts") {
		t.Fatalf("JSON does not contain the proper path: %s", string(jsonData))
	}

	unmarshalledConfig := config.NewConfig(version)
	err = json.Unmarshal(jsonData, &unmarshalledConfig)

	w.BailIfErrorf(err, "deserialization failed: %v", err)

	_, err = FromConfig(unmarshalledConfig)

	w.BailIfErrorf(err, "reinstation of fs provider failed: %v", err)
}
開發者ID:DirtyHairy,項目名稱:csync,代碼行數:28,代碼來源:marshalling_test.go

示例11: getOSReleases

func getOSReleases() (Releases, error) {
	res, err := http.Get("https://api.github.com/repos/nlf/dlite-os/releases")
	if err != nil {
		return nil, err
	}

	defer res.Body.Close()
	releases := Releases{}
	decoder := json.NewDecoder(res.Body)
	err = decoder.Decode(&releases)
	if err != nil {
		return nil, err
	}

	allowedReleases := Releases{}
	for _, release := range releases {
		release.Version = semver.MustParse(strings.TrimPrefix(release.Tag, "v"))
		if allowedRange(release.Version) {
			allowedReleases = append(allowedReleases, release)
		}
	}

	sort.Sort(allowedReleases)
	return allowedReleases, nil
}
開發者ID:nlf,項目名稱:dlite,代碼行數:25,代碼來源:os.go

示例12: CheckDockerVersion

// CheckDockerVersion checks that the appropriate Docker version is installed based on whether we are using the nsenter mounter
// or shared volumes for OpenShift
func (c *ClientStartConfig) CheckDockerVersion(io.Writer) error {
	var minDockerVersion semver.Version
	if c.UseNsenterMount {
		minDockerVersion = semver.MustParse("1.8.1")
	} else {
		minDockerVersion = semver.MustParse("1.10.0")
	}
	ver, err := c.DockerHelper().Version()
	if err != nil {
		return err
	}
	glog.V(5).Infof("Checking that docker version is at least %v", minDockerVersion)
	if ver.LT(minDockerVersion) {
		return fmt.Errorf("Docker version is %v, it needs to be %v", ver, minDockerVersion)
	}
	return nil
}
開發者ID:bmeng,項目名稱:origin,代碼行數:19,代碼來源:up.go

示例13: validate

func validate(deps map[string][]semver.Version, expected map[string]string, t *testing.T) {
	for name, ver := range expected {
		vers, ok := deps[name]
		if !ok || !exists(vers, semver.MustParse(ver)) {
			t.Fatalf("Expected ver %s for %s, got: %v", ver, name, vers)
		}
	}
}
開發者ID:AgFlow,項目名稱:jsversion,代碼行數:8,代碼來源:versions_test.go

示例14: main

func main() {
	customRawPrevVersion := flag.String("prev", "", "Force a previous version number")
	var customPrevVersion *semver.Version
	flag.Parse()

	if *customRawPrevVersion != "" {
		tmp := semver.MustParse(*customRawPrevVersion)
		customPrevVersion = &tmp
	}

	args := flag.Args()
	endRev := "HEAD"
	startRev := ""

	repoPath, err := GetRepoPath()
	tags := getTags(repoPath)

	var newVersion *semver.Version
	var oldVersion *semver.Version
	if err != nil {
		log.Fatalf("Failed to open repository: %s", err.Error())
	}
	if len(args) == 0 {
		startRev, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		if err != nil {
			log.Fatalf("Failed to retrieve previous version: %s", err.Error())
		}
	} else if len(args) == 1 {
		_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		startRev = args[0]
	} else {
		startRev = args[0]
		_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		endRev = args[1]
	}

	if customPrevVersion != nil {
		oldVersion = customPrevVersion
	}

	if oldVersion == nil {
		log.Println("No previous version found")
		newVersion = &semver.Version{Major: 1, Minor: 0, Patch: 0}
	}

	if oldVersion != nil {
		log.Printf("Previous version: %s (%s)\n", oldVersion, startRev)
	}

	if newVersion == nil {
		newVersion, err = getNewVersion(repoPath, startRev, endRev, oldVersion, tags)
		if err != nil {
			log.Fatalf("Failed to generate new version: %s", err.Error())
		}
	}

	fmt.Println(newVersion)
}
開發者ID:zerok,項目名稱:gensemver,代碼行數:58,代碼來源:main.go

示例15: UnmarshalYAML

// UnmarshalYAML is a overridden implementation of YAML parsing the component.yaml
// This method is similar to the one found here: http://choly.ca/post/go-json-marshalling/
// This is necessary because we want to have backwards compatibility with parsing the old types of version 2.0
// (type =float).
// To compensate for that, we have to hand roll our own UnmarshalYAML that can decide what to do for parsing
// the older version of type float and converting it into semver. In addition, we will use this logic to parse strings
// into semver.
func (b *Base) UnmarshalYAML(unmarshal func(v interface{}) error) error {
	// When we call "unmarshal" callback on an object, it will call that object's "UnmarshalYAML" if defined.
	// Since we are currently in the implementation of Component's "UnmarshalYAML", when finally we call
	// unmarshal again, if it's on type Component, we would end up in a recursive infinite loop.
	// To prevent this, we create a separate type, called Alias.
	type Alias Base
	// Create an anonymous struct with an interface{} type for the schema_version that we want to parse
	aux := &struct {
		SchemaVersion interface{} `yaml:"schema_version" json:"schema_version"`
		Alias         `yaml:",inline"`
	}{
		Alias: (Alias)(*b),
	}

	// Call unmarshal on the new Alias type. Don't return the error yet because we want to gather more information
	// if we can below.
	err := unmarshal(&aux)

	// Create a placeholder variable for the converted semver.
	var ver semver.Version
	// Create a placeholder variable for the error.
	var versionErr error

	// Store the version value for conciseness.
	value := aux.SchemaVersion

	// Try to cast the value from interface{} to certain types.
	switch v := value.(type) {
	// For float types, which are the old types, we need to upcast it to semver if it's an older version.
	case float32, float64:
		switch v {
		// Schema Version started being documented with "2.0".
		// We should be able to parse it for backwards compatibility.
		// All future versioning should be in semver format already.
		case 2.0:
			ver = semver.MustParse("2.0.0")
		// If not the older version, it needs to be in semver format, send an error.
		default:
			return BaseComponentParseError{fmt.Sprintf("Version %v is not in semver format", v)}

		}
	// The interface type will default to string if not numeric which is what all semver types will be initially.
	case string:
		ver, versionErr = semver.Parse(v)
		if versionErr != nil {
			return BaseComponentParseError{constants.ErrMissingVersion}
		}
	// In the case, it's just missing completely.
	default:
		return BaseComponentParseError{constants.ErrMissingVersion}
	}
	// Copy everything from the Alias back to the original component.
	*b = (Base)(aux.Alias)

	// Get the version
	b.SchemaVersion = ver
	return err
}
開發者ID:opencontrol,項目名稱:compliance-masonry,代碼行數:65,代碼來源:component.go


注:本文中的github.com/blang/semver.MustParse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。