本文整理匯總了Golang中github.com/blang/semver.Version.EQ方法的典型用法代碼示例。如果您正苦於以下問題:Golang Version.EQ方法的具體用法?Golang Version.EQ怎麽用?Golang Version.EQ使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/blang/semver.Version
的用法示例。
在下文中一共展示了Version.EQ方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
//.........這裏部分代碼省略.........
示例2: 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
}