本文整理汇总了Golang中github.com/blang/semver.Version类的典型用法代码示例。如果您正苦于以下问题:Golang Version类的具体用法?Golang Version怎么用?Golang Version使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Version类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Apply
func (PatchBump) Apply(v semver.Version) semver.Version {
v.Patch++
v.Pre = nil
return v
}
开发者ID:xtreme-sameer-vohra,项目名称:semver-resource,代码行数:5,代码来源:patch_bump.go
注:本文中的github.com/blang/semver.Version类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论