linuxdo

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package linuxdo is the library behind the linuxdo command: the HTTP client, request shaping, and the typed data models for linux.do.

The client fetches from the public Discourse JSON API at https://linux.do. No authentication is required. It sets a real User-Agent, paces requests, and retries transient 429/5xx errors with exponential backoff.

Index

Constants

View Source
const DefaultUserAgent = "linuxdo/dev (+https://github.com/tamnd/linuxdo-cli)"

DefaultUserAgent identifies the client to linux.do.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the linux.do Discourse JSON API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) Topics

func (c *Client) Topics(ctx context.Context, path string) ([]TopicRecord, error)

Topics fetches topics from the given path (e.g. "/hot.json", "/latest.json", "/top/weekly.json") and returns the parsed list as TopicRecord values.

type Config

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

Config holds constructor parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for linux.do.

type Topic

type Topic struct {
	ID         int    `json:"id"`
	Title      string `json:"title"`
	Slug       string `json:"slug"`
	ReplyCount int    `json:"reply_count"`
	CreatedAt  string `json:"created_at"`
	LikeCount  int    `json:"like_count"`
	Views      int    `json:"views"`
}

Topic is a single Discourse topic record.

type TopicList

type TopicList struct {
	TopicList struct {
		Topics []Topic `json:"topics"`
	} `json:"topic_list"`
}

TopicList is the JSON envelope returned by the Discourse API.

type TopicRecord

type TopicRecord struct {
	Rank    int    `json:"rank"`
	Title   string `json:"title"`
	Replies int    `json:"replies"`
	Created string `json:"created"`
	Likes   int    `json:"likes"`
	Views   int    `json:"views"`
	URL     string `json:"url"`
}

TopicRecord is the output record emitted for every command.

Jump to

Keyboard shortcuts

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