lemmy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package lemmy is the library behind the lemmy command line: the HTTP client, request shaping, and the typed data models for the Lemmy federated forum API at lemmy.world.

The Lemmy REST API is open for public read-only data: no API key, no auth required. This package wraps the v3 API with a rate-limited client that the kit operations consume.

Index

Constants

View Source
const DefaultUserAgent = "lemmy-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to lemmy.world honestly.

View Source
const Host = "lemmy.world"

Host is the default Lemmy instance this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a rate-limited HTTP client for the Lemmy v3 API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) GetSite

func (c *Client) GetSite(ctx context.Context) (*Site, error)

GetSite fetches instance statistics.

func (*Client) ListComments

func (c *Client) ListComments(ctx context.Context, postID, limit int) ([]Comment, error)

ListComments fetches comments on a post.

func (*Client) ListCommunities

func (c *Client) ListCommunities(ctx context.Context, sort, listType string, limit int) ([]Community, error)

ListCommunities fetches communities from the Lemmy API. sort: Active, Hot, New, TopDay, TopMonth, TopYear, TopAll (default: Active) listType: All, Local (default: All)

func (*Client) ListPosts

func (c *Client) ListPosts(ctx context.Context, sort, listType string, limit int) ([]Post, error)

ListPosts fetches posts from the Lemmy API. sort: Active, Hot, New, TopDay, TopWeek, TopMonth (default: Active) listType: All, Local, Subscribed (default: All)

func (*Client) Search

func (c *Client) Search(ctx context.Context, query, searchType, sort string, limit int) (*wireSearchResp, error)

Search searches for posts, communities, or comments. searchType: Posts, Communities, Comments, Users (default: Posts) sort: Active, Hot, New, TopAll (default: TopAll)

type Comment

type Comment struct {
	ID        int    `json:"id" kit:"id"`
	Content   string `json:"content"`
	Author    string `json:"author"`
	Score     int    `json:"score"`
	Published string `json:"published"`
	PostID    int    `json:"post_id"`
}

Comment is a single Lemmy comment record.

type Community

type Community struct {
	ID          int    `json:"id" kit:"id"`
	Name        string `json:"name"`
	Title       string `json:"title"`
	Description string `json:"description"`
	ActorID     string `json:"actor_id"`
	Subscribers int    `json:"subscribers"`
	Posts       int    `json:"posts"`
	Comments    int    `json:"comments"`
	Published   string `json:"published"`
}

Community is a single Lemmy community record.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for lemmy.world.

type Domain

type Domain struct{}

Domain is the Lemmy driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (uriType, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme and the identity the single-site binary inherits.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the canonical URL for a (uriType, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Post

type Post struct {
	ID        int    `json:"id" kit:"id"`
	Title     string `json:"title"`
	URL       string `json:"url"`
	Body      string `json:"body"`
	Community string `json:"community"`
	Author    string `json:"author"`
	Score     int    `json:"score"`
	Comments  int    `json:"comments"`
	Published string `json:"published"`
	NSFW      bool   `json:"nsfw"`
	PostURL   string `json:"post_url"`
}

Post is a single Lemmy post record.

type Site

type Site struct {
	Name        string `json:"name" kit:"id"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Users       int    `json:"users"`
	Posts       int    `json:"posts"`
	Comments    int    `json:"comments"`
	Communities int    `json:"communities"`
}

Site is instance-level statistics for a Lemmy instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL