本文整理汇总了Golang中github.com/apex/log.Interface.Infof方法的典型用法代码示例。如果您正苦于以下问题:Golang Interface.Infof方法的具体用法?Golang Interface.Infof怎么用?Golang Interface.Infof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/apex/log.Interface
的用法示例。
在下文中一共展示了Interface.Infof方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Selfupdate
// Selfupdate runs a self-update for the current binary
func Selfupdate(ctx log.Interface, component string) {
if viper.GetString("gitBranch") == "unknown" {
ctx.Infof("You are not using an official %s build. Not proceeding with the update", component)
return
}
info, err := GetLatestInfo()
if err != nil {
ctx.WithError(err).Fatal("Could not get version information from the server")
}
if viper.GetString("gitCommit") == info.Commit {
ctx.Info("The git commit of the build on the server is the same as yours")
ctx.Info("Not proceeding with the update")
return
}
if date, err := time.Parse(time.RFC3339, viper.GetString("buildDate")); err == nil {
if date.Equal(info.Date) {
ctx.Infof("You have the latest version of %s", component)
ctx.Info("Nothing to update")
return
}
if date.After(info.Date) {
ctx.Infof("Your build is %s newer than the build on the server", date.Sub(info.Date))
ctx.Info("Not proceeding with the update")
return
}
ctx.Infof("The build on the server is %s newer than yours", info.Date.Sub(date))
}
ctx.Infof("Downloading the latest %s...", component)
binary, err := GetLatest(component)
if err != nil {
ctx.WithError(err).Fatal("Could not download latest binary")
}
filename, err := osext.Executable()
if err != nil {
ctx.WithError(err).Fatal("Could not get path to local binary")
}
stat, err := os.Stat(filename)
if err != nil {
ctx.WithError(err).Fatal("Could not stat local binary")
}
ctx.Info("Replacing local binary...")
if err := ioutil.WriteFile(filename+".new", binary, stat.Mode()); err != nil {
ctx.WithError(err).Fatal("Could not write new binary to filesystem")
}
if err := os.Rename(filename, filename+".old"); err != nil {
ctx.WithError(err).Fatal("Could not rename binary")
}
if err := os.Rename(filename+".new", filename); err != nil {
ctx.WithError(err).Fatal("Could not rename binary")
}
ctx.Infof("Updated %s to the latest version", component)
}