birdbot/mastodon/mastodon.go
2023-03-31 20:49:50 +00:00

31 lines
618 B
Go

package mastodon
import (
"context"
"log"
"github.com/mattn/go-mastodon"
)
type Mastodon struct {
client *mastodon.Client
}
// NewMastodon initializes a new Mastodon client
func NewMastodon(server string, clientID string, clientSecret string, username string, password string) *Mastodon {
m := &Mastodon{}
m.client = mastodon.NewClient(&mastodon.Config{
Server: server,
ClientID: clientID,
ClientSecret: clientSecret,
})
err := m.client.Authenticate(context.Background(), username, password)
if err != nil {
log.Print("Failed to configure Mastodon: ", err)
return nil
}
return m
}