Documentation
¶
Overview ¶
Package lemmy is a dependency-free read client for the Lemmy REST API (/api/v3). It targets CGO_ENABLED=0 builds and uses only the Go standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Instance is the base URL of the Lemmy instance,
// e.g. https://lemmy.world.
Instance string
// HTTPClient is used for all requests. Defaults to http.DefaultClient.
HTTPClient *http.Client
// UserAgent is sent with every request.
UserAgent string
// contains filtered or unexported fields
}
Client is a read client for a single Lemmy instance.
func New ¶
New returns a Client for the given instance base URL (e.g. https://lemmy.world). Trailing slashes are trimmed.
func (*Client) Login ¶
Login POSTs /api/v3/user/login and stores the returned jwt for subsequent requests.
func (*Client) SearchCommunities ¶ added in v0.2.0
func (c *Client) SearchCommunities(ctx context.Context, query string, limit int) (*CommunityList, error)
SearchCommunities GETs /api/v3/search?type_=Communities for communities matching query — a public read used to discover communities to subscribe to. limit caps the page (0 → 20).
type Community ¶ added in v0.2.0
type Community struct {
Name string
Title string
Description string
Icon string
ActorID string
Subscribers int
NSFW bool
}
Community is one community-search hit: enough to show a discovery row and subscribe. Name is the local handle ("golang"); ActorID is the federated URL ("https://lemmy.world/c/golang") that identifies it across instances.
type CommunityList ¶ added in v0.2.0
type CommunityList struct {
Communities []Community
}
CommunityList is a page of community-search results.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets the http.Client used for requests.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header sent with every request.
type Post ¶
type Post struct {
ID int
Title string
URL string
Body string
Permalink string
ThumbnailURL string
Published time.Time
NSFW bool
Creator string
Community string
Score int
Comments int
}
Post is a flattened view of a Lemmy post.
type PostsOptions ¶
type PostsOptions struct {
Community string // community name; empty = instance-wide
Sort string // Active|Hot|New|Top...; default "Hot"
Type string // All|Local|Subscribed; default "All"
Limit int // default 20
Page int // 1-based; default 1
}
PostsOptions configures a Posts request.
