79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/rs/zerolog/log"
|
|
"net/http"
|
|
"time"
|
|
//"github.com/bitly/go-simplejson"
|
|
)
|
|
|
|
type ServerImplementation int
|
|
|
|
const (
|
|
ServerUnknown ServerImplementation = iota
|
|
ServerMastodon
|
|
ServerPleorama
|
|
)
|
|
|
|
type Instance struct {
|
|
hostName string
|
|
impl ServerImplementation
|
|
errorCount uint
|
|
lastFetch *time.Time
|
|
highestId int
|
|
skip bool
|
|
}
|
|
|
|
func NewInstance(hostname string) *Instance {
|
|
i := new(Instance)
|
|
i.hostName = hostname
|
|
i.detectNodeType()
|
|
return i
|
|
}
|
|
|
|
func (i *Instance) detectNodeType() {
|
|
if i.impl > ServerUnknown {
|
|
return
|
|
}
|
|
}
|
|
|
|
func (i *Instance) fetchNodeInfo() {
|
|
url := fmt.Sprintf("https://%s/.well-known/nodeinfo")
|
|
var c = &http.Client{
|
|
Timeout: time.Second * 10,
|
|
}
|
|
response, err := c.Get(url)
|
|
if err != nil {
|
|
log.Debug().Msg("unable to fetch nodeinfo, node is down?")
|
|
i.skip = true
|
|
}
|
|
|
|
log.Debug().Msg(fmt.Sprintf("%#v", response))
|
|
}
|
|
|
|
func (i *Instance) fetchRecentToots() ([]byte, error) {
|
|
if i.impl == Mastodon {
|
|
return i.fetchRecentTootsJsonFromMastodon()
|
|
} else if i.impl == Pleorama {
|
|
return i.fetchRecentTootsJsonFromPleorama()
|
|
} else {
|
|
panic("nope")
|
|
}
|
|
}
|
|
|
|
func (i *Instance) fetchRecentTootsJsonFromPleorama() ([]byte, error) {
|
|
//url := fmt.Sprintf("https://%s/api/statuses/public_and_external_timeline.json?count=100", i.hostName)
|
|
return nil, nil
|
|
}
|
|
|
|
func (i *Instance) fetchRecentTootsJsonFromMastodon() ([]byte, error) {
|
|
//url := fmt.Sprintf("https://%s/api/v1/timelines/public?limit=40&local=true", i.hostName)
|
|
return nil, nil
|
|
}
|
|
|
|
func fetchLatestToots(lastId int) {
|
|
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")
|
|
}
|