From 92335ead98f3547afba80267f2ba721e0348af2b Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Tue, 29 Oct 2019 11:48:53 -0700 Subject: [PATCH] minor reorg --- archiver.go | 5 +---- identity.go | 36 ++++++++++++++++++++++++++++++++++++ main.go | 16 +--------------- 3 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 identity.go diff --git a/archiver.go b/archiver.go index ee2c3f7..c5c43b9 100644 --- a/archiver.go +++ b/archiver.go @@ -2,8 +2,6 @@ package main import ( "context" - "fmt" - "github.com/rs/zerolog/log" "time" //"github.com/bitly/go-simplejson" ) @@ -27,11 +25,10 @@ func (a *Archiver) Uptime() time.Duration { return time.Since(*a.startup) } -func (a *Archiver) Run() int { +func (a *Archiver) RunForever() int { t := time.Now() a.startup = &t a.locator = NewInstanceLocator() - log.Info().Msg(fmt.Sprintf("in %#v.Run()", a)) go a.locator.Locate() for { diff --git a/identity.go b/identity.go new file mode 100644 index 0000000..964dd11 --- /dev/null +++ b/identity.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/rs/zerolog/log" +) + +var Version string +var Buildtime string +var Builduser string +var Buildarch string + +type AppIdentity struct { + Version string + Buildtime string + Builduser string + Buildarch string +} + +func GetAppIdentity() *AppIdentity { + i := new(AppIdentity) + i.Version = Version + i.Buildtime = Buildtime + i.Builduser = Builduser + i.Buildarch = Buildarch + return i +} + +func identify() { + i := GetAppIdentity() + log.Info(). + Str("version", i.Version). + Str("buildarch", i.Buildarch). + Str("buildtime", i.Buildtime). + Str("builduser", i.Builduser). + Msg("starting") +} diff --git a/main.go b/main.go index d8e1a2c..30511ea 100644 --- a/main.go +++ b/main.go @@ -9,24 +9,10 @@ import ( "os" ) -var Version string -var Buildtime string -var Builduser string -var Buildarch string - func main() { os.Exit(app()) } -func identify() { - log.Info(). - Str("version", Version). - Str("buildarch", Buildarch). - Str("buildtime", Buildtime). - Str("builduser", Builduser). - Msg("starting") -} - func app() int { log.Logger = log.With().Caller().Logger() if terminal.IsTerminal(int(os.Stdout.Fd())) { @@ -44,5 +30,5 @@ func app() int { } mainContext := context.Background() - return NewArchiver(mainContext).Run() + return NewArchiver(mainContext).RunForever() }