diff --git a/archiver.go b/archiver.go index 0ca2ff7..202a546 100644 --- a/archiver.go +++ b/archiver.go @@ -1,9 +1,9 @@ package main import ( + "context" "fmt" "github.com/rs/zerolog/log" - "net/http" "time" //"github.com/bitly/go-simplejson" ) @@ -14,13 +14,24 @@ type Archiver struct { locator *InstanceLocator instances map[InstanceHostName]*Instance startup *time.Time + ctx context.Context } -func NewArchiver() *Archiver { +func NewArchiver(ctx context.Context) *Archiver { a := new(Archiver) + a.ctx = ctx return a } -func (a *Archiver) Run() { - +func (a *Archiver) Uptime() time.Duration { + return time.Since(*a.startup) +} + +func (a *Archiver) Run() int { + t := time.Now() + a.startup = &t + a.locator = NewInstanceLocator() + log.Info().Msg(fmt.Sprintf("in %#v.Run()", a)) + a.locator.Locate() + return 0 } diff --git a/instance.go b/instance.go index 24c3d3d..0d4cbf2 100644 --- a/instance.go +++ b/instance.go @@ -49,13 +49,13 @@ func (i *Instance) fetchNodeInfo() { i.skip = true } - log.Debug().Msg(fmt.Sprintf("%#v", response)) + log.Debug().Msgf("%#v", response) } func (i *Instance) fetchRecentToots() ([]byte, error) { - if i.impl == Mastodon { + if i.impl == ServerMastodon { return i.fetchRecentTootsJsonFromMastodon() - } else if i.impl == Pleorama { + } else if i.impl == ServerPleorama { return i.fetchRecentTootsJsonFromPleorama() } else { panic("nope") diff --git a/instancelocator.go b/locator.go similarity index 64% rename from instancelocator.go rename to locator.go index 79a7f8d..74524f5 100644 --- a/instancelocator.go +++ b/locator.go @@ -1,11 +1,10 @@ package main import ( - "fmt" "github.com/rs/zerolog/log" + "io/ioutil" "net/http" "time" - //"github.com/bitly/go-simplejson" ) const mastodonIndexUrl = "https://instances.social/list.json?q%5Busers%5D=&q%5Bsearch%5D=&strict=false" @@ -22,3 +21,16 @@ func NewInstanceLocator() *InstanceLocator { i := new(InstanceLocator) return i } + +func (i *InstanceLocator) Locate() { + //var hostnames []string + + var netClient = &http.Client{ + Timeout: time.Second * 10, + } + resp, _ := netClient.Get(mastodonIndexUrl) + defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + + log.Debug().Msgf("%#v", body) +} diff --git a/main.go b/main.go index dc260d4..d8e1a2c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "flag" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -22,11 +23,12 @@ func identify() { Str("version", Version). Str("buildarch", Buildarch). Str("buildtime", Buildtime). - Str("builduser", Builduser).Send(). + Str("builduser", Builduser). Msg("starting") } func app() int { + log.Logger = log.With().Caller().Logger() if terminal.IsTerminal(int(os.Stdout.Fd())) { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) } @@ -41,5 +43,6 @@ func app() int { zerolog.SetGlobalLevel(zerolog.DebugLevel) } - return NewArchiver().Run() + mainContext := context.Background() + return NewArchiver(mainContext).Run() }