Documentation
¶
Overview ¶
Package mastodon is a dependency-free read client for the Mastodon REST API.
It uses only the Go standard library (CGO_ENABLED=0) and exposes a small surface for reading public, hashtag and per-account timelines.
Index ¶
- type Account
- type Client
- func (c *Client) AccountStatuses(ctx context.Context, acct string, opts TimelineOptions) (*Timeline, error)
- func (c *Client) HashtagTimeline(ctx context.Context, tag string, opts TimelineOptions) (*Timeline, error)
- func (c *Client) PublicTimeline(ctx context.Context, opts TimelineOptions) (*Timeline, error)
- type Media
- type Option
- type Status
- type Tag
- type Timeline
- type TimelineOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ID string `json:"id"`
Username string `json:"username"`
Acct string `json:"acct"`
DisplayName string `json:"display_name"`
URL string `json:"url"`
Avatar string `json:"avatar"`
}
Account is a Mastodon account.
type Client ¶
type Client struct {
// Instance is the base URL of the Mastodon instance,
// e.g. https://mastodon.social.
Instance string
// Token is an optional bearer token. When set, requests are
// authenticated with an Authorization header.
Token string
// HTTPClient is the underlying HTTP client. When nil, http.DefaultClient
// is used.
HTTPClient *http.Client
// UserAgent is the value sent in the User-Agent header.
UserAgent string
}
Client is a read-only Mastodon REST API client.
func (*Client) AccountStatuses ¶
func (c *Client) AccountStatuses(ctx context.Context, acct string, opts TimelineOptions) (*Timeline, error)
AccountStatuses resolves acct via GET /api/v1/accounts/lookup and then fetches that account's statuses (GET /api/v1/accounts/:id/statuses).
func (*Client) HashtagTimeline ¶
func (c *Client) HashtagTimeline(ctx context.Context, tag string, opts TimelineOptions) (*Timeline, error)
HashtagTimeline fetches the timeline for a hashtag (GET /api/v1/timelines/tag/:hashtag).
func (*Client) PublicTimeline ¶
PublicTimeline fetches the public timeline (GET /api/v1/timelines/public).
type Media ¶
type Media struct {
Type string `json:"type"` // image, video, gifv, audio
URL string `json:"url"`
PreviewURL string `json:"preview_url"`
Description string `json:"description"`
}
Media is a media attachment on a status.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used to perform requests.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header value.
type Status ¶
type Status struct {
ID string `json:"id"`
URL string `json:"url"`
Content string `json:"content"` // HTML
CreatedAt time.Time `json:"created_at"`
Account Account `json:"account"`
Favourites int `json:"favourites_count"`
Reblogs int `json:"reblogs_count"`
Replies int `json:"replies_count"`
Sensitive bool `json:"sensitive"`
SpoilerText string `json:"spoiler_text"`
Media []Media `json:"media_attachments"`
Tags []Tag `json:"tags"`
}
Status is a Mastodon status (toot).
type Timeline ¶
type Timeline struct {
Statuses []Status
// MaxID is extracted from the Link header rel="next" and can be passed
// as TimelineOptions.MaxID to fetch the following page. It is empty when
// there is no next page.
MaxID string
}
Timeline is a page of statuses plus the pagination cursor.