fetches index now
This commit is contained in:
parent
f864469860
commit
8b926e8409
19
archiver.go
19
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
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
7
main.go
7
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user