本文整理匯總了Golang中github.com/apex/log.Interface.Info方法的典型用法代碼示例。如果您正苦於以下問題:Golang Interface.Info方法的具體用法?Golang Interface.Info怎麽用?Golang Interface.Info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/apex/log.Interface
的用法示例。
在下文中一共展示了Interface.Info方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例2: configLoop
// continue looking at dns entry for changes in config
func configLoop(ctx log.Interface, cfgURL string) {
ticker := time.Tick(15 * time.Second)
for {
select {
case <-ticker:
newIPs, err := dnscfg.Get(dnsAddr, ldPort)
if err != nil {
ctx.WithError(err).Error("dns lookup")
continue
}
if len(newIPs) == 0 {
ctx.Error("no ip addresses found")
continue
}
oldIPs, err := httpcfg.Get(cfgURL)
if err != nil {
ctx.WithError(err).Error("getting config")
continue
}
if eq(newIPs, oldIPs) {
ctx.Info("config up to date")
continue
}
err = httpcfg.Set(cfgURL, newIPs)
if err != nil {
ctx.WithError(err).Error("setting config")
continue
}
ctx.WithField("ips", newIPs).Info("setting config")
}
}
}
示例3: GetRouter
// GetRouter starts a connection with the router
func GetRouter(ctx log.Interface) (*grpc.ClientConn, router.RouterClient) {
ctx.Info("Discovering Router...")
dscConn, client := GetDiscovery(ctx)
defer dscConn.Close()
routerAnnouncement, err := client.Get(GetContext(ctx), &discovery.GetRequest{
ServiceName: "router",
Id: viper.GetString("router-id"),
})
if err != nil {
ctx.WithError(errors.FromGRPCError(err)).Fatal("Could not get Router from Discovery")
}
ctx.Info("Connecting with Router...")
rtrConn, err := routerAnnouncement.Dial()
ctx.Info("Connected to Router")
rtrClient := router.NewRouterClient(rtrConn)
return rtrConn, rtrClient
}