From f86446986012cd003faee1c3c41584cb7765728b Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Thu, 24 Oct 2019 05:14:36 -0700 Subject: [PATCH] saving --- archiver.go | 26 ++++++++++++++++++++++++++ fetcher.go => instance.go | 17 ++++------------- instancelocator.go | 24 ++++++++++++++++++++++++ main.go | 13 ++++--------- 4 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 archiver.go rename fetcher.go => instance.go (79%) create mode 100644 instancelocator.go diff --git a/archiver.go b/archiver.go new file mode 100644 index 0000000..0ca2ff7 --- /dev/null +++ b/archiver.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/rs/zerolog/log" + "net/http" + "time" + //"github.com/bitly/go-simplejson" +) + +type InstanceHostName string + +type Archiver struct { + locator *InstanceLocator + instances map[InstanceHostName]*Instance + startup *time.Time +} + +func NewArchiver() *Archiver { + a := new(Archiver) + return a +} + +func (a *Archiver) Run() { + +} diff --git a/fetcher.go b/instance.go similarity index 79% rename from fetcher.go rename to instance.go index f909977..24c3d3d 100644 --- a/fetcher.go +++ b/instance.go @@ -8,21 +8,12 @@ import ( //"github.com/bitly/go-simplejson" ) -const mastodonIndexUrl = "https://instances.social/list.json?q%5Busers%5D=&q%5Bsearch%5D=&strict=false" - -const pleromaIndexUrl = "https://distsn.org/cgi-bin/distsn-pleroma-instances-api.cgi" - -type InstanceLocator struct { - pleromaIndexLastRefresh *time.Time - mastodonIndexLastRefresh *time.Time - instances map[string]Instance -} - type ServerImplementation int const ( - Mastodon ServerImplementation = iota + 1 - Pleorama + ServerUnknown ServerImplementation = iota + ServerMastodon + ServerPleorama ) type Instance struct { @@ -42,7 +33,7 @@ func NewInstance(hostname string) *Instance { } func (i *Instance) detectNodeType() { - if i.impl == 0 { + if i.impl > ServerUnknown { return } } diff --git a/instancelocator.go b/instancelocator.go new file mode 100644 index 0000000..79a7f8d --- /dev/null +++ b/instancelocator.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "github.com/rs/zerolog/log" + "net/http" + "time" + //"github.com/bitly/go-simplejson" +) + +const mastodonIndexUrl = "https://instances.social/list.json?q%5Busers%5D=&q%5Bsearch%5D=&strict=false" + +const pleromaIndexUrl = "https://distsn.org/cgi-bin/distsn-pleroma-instances-api.cgi" + +type InstanceLocator struct { + pleromaIndexLastRefresh *time.Time + mastodonIndexLastRefresh *time.Time + instances map[string]Instance +} + +func NewInstanceLocator() *InstanceLocator { + i := new(InstanceLocator) + return i +} diff --git a/main.go b/main.go index b6c2162..dc260d4 100644 --- a/main.go +++ b/main.go @@ -18,11 +18,12 @@ func main() { } func identify() { - log.Debug(). + log.Info(). Str("version", Version). Str("buildarch", Buildarch). Str("buildtime", Buildtime). - Str("builduser", Builduser).Send() + Str("builduser", Builduser).Send(). + Msg("starting") } func app() int { @@ -35,16 +36,10 @@ func app() int { identify() - log.Print("hello world") - - // Default level for this example is info, unless debug flag is present zerolog.SetGlobalLevel(zerolog.InfoLevel) if *debug { zerolog.SetGlobalLevel(zerolog.DebugLevel) } - log.Debug().Msg("This message appears only when log level set to Debug") - log.Info().Msg("This message appears when log level set to Debug or Info") - - return 0 + return NewArchiver().Run() }