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


Golang Version.String方法代碼示例

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


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

示例1: set

func set(v semver.Version) {
	err := ioutil.WriteFile(file, []byte(v.String()), os.ModeExclusive)
	if err != nil {
		fmt.Printf("Unable to write version file: %v", err)
		os.Exit(3)
	}
	fmt.Printf("New version: %s", v)
}
開發者ID:fabric8io,項目名稱:gobump,代碼行數:8,代碼來源:gobump.go

示例2: main

func main() {
	if len(os.Args) < 2 {
		println("usage: " + os.Args[0] + " <source>")
		os.Exit(1)
	}

	sources := os.Args[1]

	var request models.OutRequest
	err := json.NewDecoder(os.Stdin).Decode(&request)
	if err != nil {
		fatal("reading request", err)
	}

	driver, err := driver.FromSource(request.Source)
	if err != nil {
		fatal("constructing driver", err)
	}

	var newVersion semver.Version
	if request.Params.File != "" {
		versionFile, err := os.Open(filepath.Join(sources, request.Params.File))
		if err != nil {
			fatal("opening version file", err)
		}

		defer versionFile.Close()

		var versionStr string
		_, err = fmt.Fscanf(versionFile, "%s", &versionStr)
		if err != nil {
			fatal("reading version file", err)
		}

		newVersion, err = semver.Parse(versionStr)
		if err != nil {
			fatal("parsing version", err)
		}

		err = driver.Set(newVersion)
		if err != nil {
			fatal("setting version", err)
		}
	} else if request.Params.Bump != "" || request.Params.Pre != "" {
		bump := version.BumpFromParams(request.Params.Bump, request.Params.Pre)

		newVersion, err = driver.Bump(bump)
		if err != nil {
			fatal("bumping version", err)
		}
	} else {
		println("no version bump specified")
		os.Exit(1)
	}

	outVersion := models.Version{
		Number: newVersion.String(),
	}

	json.NewEncoder(os.Stdout).Encode(models.OutResponse{
		Version: outVersion,
		Metadata: models.Metadata{
			{"number", outVersion.Number},
		},
	})
}
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:66,代碼來源:main.go

示例3:

		"":      "1.2.3",
		"final": "1.2.3",
		"patch": "1.2.4",
		"minor": "1.3.0",
		"major": "2.0.0",
	} {
		bumpLocal := bump
		resultLocal := result

		Context(fmt.Sprintf("when bumping %s", bumpLocal), func() {
			BeforeEach(func() {
				bumpParam = bumpLocal
			})

			It("bumps to "+resultLocal, func() {
				Ω(version.String()).Should(Equal(resultLocal))
			})
		})
	}

	Context("when bumping to a prerelease", func() {
		BeforeEach(func() {
			preParam = "rc"
		})

		for bump, result := range map[string]string{
			"":      "1.2.3-rc.1",
			"final": "1.2.3-rc.1",
			"patch": "1.2.4-rc.1",
			"minor": "1.3.0-rc.1",
			"major": "2.0.0-rc.1",
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:31,代碼來源:bump_from_params_test.go


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