feta/instance.go

79 lines
1.7 KiB
Go
Raw Normal View History

2019-10-24 10:38:16 +00:00
package main
import (
2019-10-24 11:56:44 +00:00
"fmt"
2019-10-24 10:38:16 +00:00
"github.com/rs/zerolog/log"
2019-10-24 11:56:44 +00:00
"net/http"
"time"
//"github.com/bitly/go-simplejson"
2019-10-24 10:38:16 +00:00
)
2019-10-24 11:56:44 +00:00
type ServerImplementation int
const (
2019-10-24 12:14:36 +00:00
ServerUnknown ServerImplementation = iota
ServerMastodon
ServerPleorama
2019-10-24 11:56:44 +00:00
)
type Instance struct {
hostName string
impl ServerImplementation
errorCount uint
lastFetch *time.Time
highestId int
skip bool
2019-10-24 10:38:16 +00:00
}
2019-10-24 11:56:44 +00:00
func NewInstance(hostname string) *Instance {
i := new(Instance)
i.hostName = hostname
i.detectNodeType()
return i
}
func (i *Instance) detectNodeType() {
2019-10-24 12:14:36 +00:00
if i.impl > ServerUnknown {
2019-10-24 11:56:44 +00:00
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
}
2019-10-24 12:41:05 +00:00
log.Debug().Msgf("%#v", response)
2019-10-24 11:56:44 +00:00
}
func (i *Instance) fetchRecentToots() ([]byte, error) {
2019-10-24 12:41:05 +00:00
if i.impl == ServerMastodon {
2019-10-24 11:56:44 +00:00
return i.fetchRecentTootsJsonFromMastodon()
2019-10-24 12:41:05 +00:00
} else if i.impl == ServerPleorama {
2019-10-24 11:56:44 +00:00
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
}
2019-10-24 10:38:16 +00:00
2019-10-24 11:56:44 +00:00
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) {
2019-10-24 10:38:16 +00:00
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")
}