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


Golang semver.Version類代碼示例

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


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

示例1: checkVersion

func checkVersion(v semver.Version) {
	fmt.Println("Current version is", cfg.version)
	if v.LT(cfg.version) {
		cfg.ForceCheck = true
		log.Println("Checking entire tumblrblog due to new version.")
	}
}
開發者ID:Liru,項目名稱:tumblr-downloader,代碼行數:7,代碼來源:database.go

示例2: MaybeUpdate

func MaybeUpdate(output io.Writer, githubOwner, githubRepo, binaryName, lastUpdatePath string, localVersion semver.Version) {

	downloadBinary := binaryName + "-" + runtime.GOOS + "-" + runtime.GOARCH
	updateLinkPrefix := "https://github.com/" + githubOwner + "/" + githubRepo + "/releases/tag/" + version.VersionPrefix
	downloadLinkFormat := "https://github.com/" + githubOwner + "/" + githubRepo + "/releases/download/v%s/%s"

	if !shouldCheckURLVersion(lastUpdatePath) {
		return
	}
	latestVersion, err := getLatestVersionFromGitHub(githubOwner, githubRepo)
	if err != nil {
		glog.Errorln(err)
		return
	}
	if localVersion.Compare(latestVersion) < 0 {
		writeTimeToFile(lastUpdatePath, time.Now().UTC())
		fmt.Fprintf(output, `There is a newer version of %s available. Do you want to
automatically update from %s%s to %s%s now? [y/N] `,
			binaryName, version.VersionPrefix, localVersion, version.VersionPrefix, latestVersion)

		var confirm string
		fmt.Scanln(&confirm)

		if confirm == "y" {
			fmt.Printf("Updating to version %s\n", latestVersion)
			updateBinary(latestVersion, downloadBinary, updateLinkPrefix, downloadLinkFormat)
			return
		}

		fmt.Println("Skipping autoupdate")
	}
}
開發者ID:rawlingsj,項目名稱:gofabric8,代碼行數:32,代碼來源:update.go

示例3: 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

示例4: bump

func bump(p versionPart, v semver.Version) semver.Version {
	switch p {
	case major:
		v.Major++
		v.Minor = 0
		v.Patch = 0
	case minor:
		v.Minor++
		v.Patch = 0
	case patch:
		v.Patch++
	}
	return v
}
開發者ID:fabric8io,項目名稱:gobump,代碼行數:14,代碼來源:gobump.go

示例5: Apply

func (bump PreBump) Apply(v semver.Version) semver.Version {
	if v.Pre == nil || v.Pre[0].VersionStr != bump.Pre {
		v.Pre = []semver.PRVersion{
			{VersionStr: bump.Pre},
			{VersionNum: 1, IsNum: true},
		}
	} else {
		v.Pre = []semver.PRVersion{
			{VersionStr: bump.Pre},
			{VersionNum: v.Pre[1].VersionNum + 1, IsNum: true},
		}
	}

	return v
}
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:15,代碼來源:pre_bump.go

示例6: performVersionNegotiatedRequestsToNSQD

func (s *httpServer) performVersionNegotiatedRequestsToNSQD(
	nsqlookupdAddrs []string, nsqdAddrs []string,
	deprecatedURI string, v1URI string, queryString string) {
	var err error
	// get producer structs in one set of up-front requests
	// so we can negotiate versions
	//
	// (this returns an empty list if there are no nsqlookupd configured)
	producers, _ := lookupd.GetLookupdProducers(nsqlookupdAddrs)
	for _, addr := range nsqdAddrs {
		var nodeVer semver.Version

		uri := deprecatedURI
		producer := producerSearch(producers, addr)
		if producer != nil {
			nodeVer = producer.VersionObj
		} else {
			// we couldn't find the node in our list
			// so ask it for a version directly
			nodeVer, err = lookupd.GetVersion(addr)
			if err != nil {
				s.ctx.nsqadmin.logf("ERROR: failed to get nsqd %s version - %s", addr, err)
			}
		}

		if nodeVer.NE(semver.Version{}) && nodeVer.GTE(v1EndpointVersion) {
			uri = v1URI
		}

		endpoint := fmt.Sprintf("http://%s/%s?%s", addr, uri, queryString)
		s.ctx.nsqadmin.logf("NSQD: querying %s", endpoint)
		_, err := http_api.NegotiateV1("POST", endpoint, nil)
		if err != nil {
			s.ctx.nsqadmin.logf("ERROR: nsqd %s - %s", endpoint, err)
			continue
		}
	}
}
開發者ID:zhangyuchen0411,項目名稱:nsq,代碼行數:38,代碼來源:http.go

示例7: EnsureDockerInContainer

// Ensures that the Docker daemon is in the desired container.
// Temporarily export the function to be used by dockershim.
// TODO(yujuhong): Move this function to dockershim once kubelet migrates to
// dockershim as the default.
func EnsureDockerInContainer(dockerVersion semver.Version, oomScoreAdj int, manager *fs.Manager) error {
	type process struct{ name, file string }
	dockerProcs := []process{{dockerProcessName, dockerPidFile}}
	if dockerVersion.GTE(containerdVersion) {
		dockerProcs = append(dockerProcs, process{containerdProcessName, containerdPidFile})
	}
	var errs []error
	for _, proc := range dockerProcs {
		pids, err := getPidsForProcess(proc.name, proc.file)
		if err != nil {
			errs = append(errs, fmt.Errorf("failed to get pids for %q: %v", proc.name, err))
			continue
		}

		// Move if the pid is not already in the desired container.
		for _, pid := range pids {
			if err := ensureProcessInContainerWithOOMScore(pid, oomScoreAdj, manager); err != nil {
				errs = append(errs, fmt.Errorf("errors moving %q pid: %v", proc.name, err))
			}
		}
	}
	return utilerrors.NewAggregate(errs)
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:27,代碼來源:container_manager_linux.go

示例8: New

// Create and initialize a new application. This is a front gate for
// the framework, since you should start by creating a new app struct.
// Every application should have a valid name (tag) and a version. So
// this function makes sure they have been passed and are all valid.
// Generally, you should not be creating more than one application.
func New(name, version string) *App {
	var room = make(map[string]interface{})
	const url = "https://github.com/ts33kr/boot"
	const ename = "name is not of correct format"
	const eversion = "version is not valid semver"
	pattern := regexp.MustCompile("^[a-zA-Z0-9-_]+$")
	var parsed semver.Version = semver.MustParse(version)
	if !pattern.MatchString(name) {
		panic(ename)
	}
	if parsed.Validate() != nil {
		panic(eversion)
	}
	application := &App{Name: name, Version: parsed}
	application.Storage = Storage{Container: room}
	application.CronEngine = cron.New() // create CRON
	application.Servers = make(map[string]*http.Server)
	application.Reference = shortuuid.New() // V4
	application.Providers = make([]*Provider, 0)
	application.Services = make([]*Service, 0)
	application.TimeLayout = time.RFC850
	application.Namespace = url // set
	return application          // prepared app
}
開發者ID:ts33kr,項目名稱:boot,代碼行數:29,代碼來源:app.go

示例9: 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

示例10: FixVersionClash

func FixVersionClash(g *libkb.GlobalContext, cl libkb.CommandLine) (err error) {
	var cli keybase1.ConfigClient
	var ctlCli keybase1.CtlClient
	var serviceConfig keybase1.Config
	var socket net.Conn

	g.Log.Debug("+ FixVersionClash")
	defer func() {
		if socket != nil {
			socket.Close()
			socket = nil
		}
		g.Log.Debug("- FixVersionClash -> %v", err)
	}()

	// Make our own stack here, circumventing all of our libraries, so
	// as not to introduce any incompatibilities with earlier services
	// (like 1.0.8)
	socket, err = g.SocketInfo.DialSocket()
	if err != nil {
		g.Log.Debug("| Failed to DialSocket, but ignoring error: %s\n", err)
		return nil
	}
	xp := libkb.NewTransportFromSocket(g, socket)
	srv := rpc.NewServer(xp, libkb.WrapError)
	gcli := rpc.NewClient(xp, libkb.ErrorUnwrapper{})
	cli = keybase1.ConfigClient{Cli: gcli}
	srv.Register(NewLogUIProtocol())

	serviceConfig, err = cli.GetConfig(context.TODO(), 0)
	if err != nil {
		return err
	}
	g.Log.Debug("| Contacted service; got version: %s", serviceConfig.Version)

	// We'll check and restart the service if there is a new version.
	var semverClient, semverService semver.Version

	cliVersion := libkb.VersionString()
	if g.Env.GetRunMode() == libkb.DevelRunMode {
		tmp := os.Getenv("KEYBASE_SET_VERSION")
		if len(tmp) > 0 {
			cliVersion = tmp
		}
	}

	semverClient, err = semver.Make(cliVersion)
	if err != nil {
		return err
	}
	semverService, err = semver.Make(serviceConfig.Version)
	if err != nil {
		return err
	}

	g.Log.Debug("| version check %s v %s", semverClient, semverService)
	if semverClient.EQ(semverService) {
		g.Log.Debug("| versions check out")
		return nil
	} else if semverClient.LT(semverService) && semverClient.Major < semverService.Major {
		return fmt.Errorf("Unexpected version clash; client is at v%s, which is significantly *less than* server at v%s",
			semverClient, semverService)
	}

	g.Log.Warning("Restarting after upgrade; service is running v%s, while v%s is available",
		semverService, semverClient)

	origPid, err := getPid(g)
	if err != nil {
		g.Log.Warning("Failed to find pid for service: %v\n", err)
	}

	if serviceConfig.ForkType == keybase1.ForkType_LAUNCHD {
		return restartLaunchdService(g, serviceConfig.Label, g.Env.GetServiceInfoPath())
	}

	ctlCli = keybase1.CtlClient{Cli: gcli}
	err = ctlCli.Stop(context.TODO(), keybase1.StopArg{})
	if err != nil && origPid >= 0 {
		// A fallback approach. I haven't seen a need for it, but it can't really hurt.
		// If we fail to restart via Stop() then revert to kill techniques.

		g.Log.Warning("Error in Stopping %d via RPC: %v; trying fallback (kill via pidfile)", origPid, err)
		time.Sleep(time.Second)
		var newPid int
		newPid, err = getPid(g)
		if err != nil {
			g.Log.Warning("No pid; shutdown must have worked (%v)", err)
		} else if newPid != origPid {
			g.Log.Warning("New service found with pid=%d; assuming restart", newPid)
			return nil
		} else {
			if err = killPid(origPid); err != nil {
				g.Log.Warning("Kill via pidfile failed: %v\n", err)
				return err
			}
			g.Log.Warning("Successful kill() on pid=%d", origPid)
		}
	}

//.........這裏部分代碼省略.........
開發者ID:qbit,項目名稱:client,代碼行數:101,代碼來源:versionfix.go

示例11:

package version_test

import (
	"github.com/blang/semver"
	"github.com/concourse/semver-resource/version"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("PreBump", func() {
	var inputVersion semver.Version
	var bump version.PreBump
	var outputVersion semver.Version

	BeforeEach(func() {
		inputVersion = semver.Version{
			Major: 1,
			Minor: 2,
			Patch: 3,
		}

		bump = version.PreBump{}
	})

	JustBeforeEach(func() {
		outputVersion = bump.Apply(inputVersion)
	})

	Context("when the version is a prerelease", func() {
		BeforeEach(func() {
			inputVersion.Pre = []semver.PRVersion{
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:31,代碼來源:pre_bump_test.go

示例12: Apply

func (MinorBump) Apply(v semver.Version) semver.Version {
	v.Minor++
	v.Patch = 0
	v.Pre = nil
	return v
}
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:6,代碼來源:minor_bump.go

示例13: FixVersionClash

func FixVersionClash(g *libkb.GlobalContext, cl libkb.CommandLine) (err error) {
	var cli keybase1.ConfigClient
	var ctlCli keybase1.CtlClient
	var serviceConfig keybase1.Config

	g.Log.Debug("+ FixVersionClash")
	defer func() {
		g.Log.Debug("- FixVersionClash -> %v", err)
	}()
	cli, err = GetConfigClient(g)
	if err != nil {
		return err
	}
	serviceConfig, err = cli.GetConfig(context.TODO(), 0)
	if err != nil {
		return err
	}
	g.Log.Debug("| Contacted service; got version: %s", serviceConfig.Version)

	// We'll check and restart the service if there is a new version.
	var semverClient, semverService semver.Version

	cliVersion := libkb.VersionString()
	if g.Env.GetRunMode() == libkb.DevelRunMode {
		tmp := os.Getenv("KEYBASE_SET_VERSION")
		if len(tmp) > 0 {
			cliVersion = tmp
		}
	}

	semverClient, err = semver.Make(cliVersion)
	if err != nil {
		return err
	}
	semverService, err = semver.Make(serviceConfig.Version)
	if err != nil {
		return err
	}

	g.Log.Debug("| version check %s v %s", semverClient, semverService)
	if semverClient.EQ(semverService) {
		g.Log.Debug("| versions check out")
		return nil
	} else if semverClient.LT(semverService) {
		return fmt.Errorf("Unexpected version clash; client is at v%s, which *less than* server at v%s",
			semverClient, semverService)
	}

	g.Log.Warning("Restarting after upgrade; service is running v%s, while v%s is available",
		semverService, semverClient)
	ctlCli, err = GetCtlClient(g)
	if err != nil {
		return err
	}
	err = ctlCli.Stop(context.TODO(), 0)
	if err != nil {
		return err
	}
	time.Sleep(10 * time.Millisecond)
	g.Log.Info("Waiting for shutdown...")
	time.Sleep(1 * time.Second)

	if serviceConfig.IsAutoForked {
		g.Log.Info("Restarting service...")
		_, err = AutoForkServer(g, cl)
	}

	return err
}
開發者ID:polluks,項目名稱:client,代碼行數:69,代碼來源:versionfix.go

示例14: Apply

func (FinalBump) Apply(v semver.Version) semver.Version {
	v.Pre = nil
	return v
}
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:4,代碼來源:final_bump.go

示例15:

package version_test

import (
	"fmt"

	"github.com/blang/semver"
	. "github.com/concourse/semver-resource/version"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("BumpForParams", func() {
	var (
		version semver.Version

		bumpParam string
		preParam  string
	)

	BeforeEach(func() {
		version = semver.Version{
			Major: 1,
			Minor: 2,
			Patch: 3,
		}

		bumpParam = ""
		preParam = ""
	})

	JustBeforeEach(func() {
開發者ID:xtreme-sameer-vohra,項目名稱:semver-resource,代碼行數:32,代碼來源:bump_from_params_test.go


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