Documentation
¶
Index ¶
- func ParsePostID(s string) (string, error)
- func ParseThingID(s string) (string, error)
- type APIError
- type Client
- func (c *Client) Comments(ctx context.Context, idOrURL string, o CommentsOptions) (Result[Thread], error)
- func (c *Client) Delete(ctx context.Context, target string) (Result[Deletion], error)
- func (c *Client) Edit(ctx context.Context, target, text string) (Result[Edited], error)
- func (c *Client) FetchHome(ctx context.Context) (int, error)
- func (c *Client) Get(ctx context.Context, path string, query url.Values) ([]byte, error)
- func (c *Client) GetJSON(ctx context.Context, path string, query url.Values, v any) (json.RawMessage, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Me(ctx context.Context) (Result[User], error)
- func (c *Client) MoreChildren(ctx context.Context, postIDOrURL string, ids []string, sort string) (Result[[]Comment], error)
- func (c *Client) Post(ctx context.Context, idOrURL string) (Result[Post], error)
- func (c *Client) PostForm(ctx context.Context, path string, form url.Values) ([]byte, error)
- func (c *Client) Reply(ctx context.Context, parent, text string) (Result[Comment], error)
- func (c *Client) Saved(ctx context.Context, o ListOptions) (Result[Page[Post]], error)
- func (c *Client) Search(ctx context.Context, query string, o SearchOptions) (Result[Page[Post]], error)
- func (c *Client) Session() *session.Session
- func (c *Client) Submit(ctx context.Context, o SubmitOptions) (Result[Submission], error)
- func (c *Client) SubredditInfo(ctx context.Context, sub string) (Result[Subreddit], error)
- func (c *Client) SubredditPosts(ctx context.Context, sub string, o ListOptions) (Result[Page[Post]], error)
- func (c *Client) User(ctx context.Context, name string) (Result[User], error)
- func (c *Client) UserComments(ctx context.Context, name string, o ListOptions) (Result[Page[Comment]], error)
- func (c *Client) UserPosts(ctx context.Context, name string, o ListOptions) (Result[Page[Post]], error)
- func (c *Client) Username(ctx context.Context) (string, error)
- type Comment
- type CommentsOptions
- type Deletion
- type Edited
- type ListOptions
- type More
- type Page
- type Post
- type Reauth
- type Result
- type SearchOptions
- type Submission
- type SubmitOptions
- type Subreddit
- type Thread
- type User
- type WriteError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParsePostID ¶
func ParseThingID ¶
ParseThingID resolves what a reply should attach to. A comment permalink wins over the post it sits under, since that is what the link points at.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Delete ¶
Delete removes your own post or comment. Reddit reports success even when the item was never yours, so this confirms the outcome before returning.
func (*Client) Edit ¶
Edit rewrites the body of your own text post or comment. Link posts have no body to edit, and Reddit refuses those.
func (*Client) MoreChildren ¶
func (*Client) PostForm ¶
PostForm submits a form-encoded body. Reddit answers write endpoints with a json envelope that carries its own error list, so callers check that too.
func (*Client) Reply ¶
Reply comments on a post or replies to another comment. parent accepts a fullname, a post id, or a post or comment URL.
func (*Client) Submit ¶
func (c *Client) Submit(ctx context.Context, o SubmitOptions) (Result[Submission], error)
Submit creates a post. Exactly one of Text or URL must be set.
func (*Client) SubredditInfo ¶
func (*Client) SubredditPosts ¶
func (*Client) UserComments ¶
type Comment ¶
type Comment struct {
ID string `json:"id"`
Fullname string `json:"fullname"`
Author string `json:"author"`
Body string `json:"body"`
Score int `json:"score"`
ScoreHidden bool `json:"score_hidden,omitempty"`
Created string `json:"created"`
Depth int `json:"depth"`
ParentID string `json:"parent_id"`
LinkID string `json:"link_id,omitempty"`
Subreddit string `json:"subreddit,omitempty"`
LinkTitle string `json:"link_title,omitempty"`
Permalink string `json:"permalink"`
IsOP bool `json:"is_op,omitempty"`
Stickied bool `json:"stickied,omitempty"`
Distinguished string `json:"distinguished,omitempty"`
Edited bool `json:"edited,omitempty"`
AuthorFlair string `json:"author_flair,omitempty"`
MyVote string `json:"my_vote,omitempty"`
Saved bool `json:"saved,omitempty"`
Replies []Comment `json:"replies,omitempty"`
MoreReplies int `json:"more_replies,omitempty"`
MoreIDs []string `json:"more_ids,omitempty"`
}
type CommentsOptions ¶
type Deletion ¶
type Deletion struct {
Fullname string `json:"fullname"`
Deleted bool `json:"deleted"`
Note string `json:"note,omitempty"`
}
Deletion reports what happened, including whether the item actually went away. Reddit answers a delete the same way whether or not the item was yours, so this is checked separately.
type Edited ¶
type Edited struct {
Kind string `json:"kind"`
Post *Post `json:"post,omitempty"`
Comment *Comment `json:"comment,omitempty"`
}
Edited is whatever the edit changed. Reddit returns the updated thing, and which field is set depends on whether it was a post or a comment.
type Post ¶
type Post struct {
ID string `json:"id"`
Fullname string `json:"fullname"`
Title string `json:"title"`
Author string `json:"author"`
Subreddit string `json:"subreddit"`
Score int `json:"score"`
UpvoteRatio float64 `json:"upvote_ratio"`
NumComments int `json:"num_comments"`
Created string `json:"created"`
URL string `json:"url"`
Permalink string `json:"permalink"`
Selftext string `json:"selftext,omitempty"`
IsSelf bool `json:"is_self"`
NSFW bool `json:"nsfw"`
Spoiler bool `json:"spoiler,omitempty"`
Stickied bool `json:"stickied,omitempty"`
Locked bool `json:"locked,omitempty"`
Archived bool `json:"archived,omitempty"`
Domain string `json:"domain,omitempty"`
Flair string `json:"flair,omitempty"`
AuthorFlair string `json:"author_flair,omitempty"`
Distinguished string `json:"distinguished,omitempty"`
PostHint string `json:"post_hint,omitempty"`
Edited bool `json:"edited,omitempty"`
MyVote string `json:"my_vote,omitempty"`
Saved bool `json:"saved,omitempty"`
Crosspost string `json:"crosspost_parent,omitempty"`
}
type Result ¶
type Result[T any] struct { Data T Raw json.RawMessage }
type SearchOptions ¶
type Submission ¶
type Submission struct {
ID string `json:"id"`
Fullname string `json:"fullname"`
URL string `json:"url"`
Subreddit string `json:"subreddit"`
Title string `json:"title"`
}
Submission is a newly created post.
type SubmitOptions ¶
type Subreddit ¶
type Subreddit struct {
ID string `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
PublicDescription string `json:"public_description,omitempty"`
Description string `json:"description,omitempty"`
Subscribers int `json:"subscribers"`
ActiveUsers int `json:"active_users"`
Created string `json:"created"`
NSFW bool `json:"nsfw"`
Type string `json:"type"`
URL string `json:"url"`
Lang string `json:"lang,omitempty"`
Subscribed bool `json:"subscribed"`
Moderator bool `json:"moderator,omitempty"`
Banned bool `json:"banned,omitempty"`
Icon string `json:"icon,omitempty"`
}
type User ¶
type User struct {
ID string `json:"id"`
Name string `json:"name"`
Created string `json:"created"`
LinkKarma int `json:"link_karma"`
CommentKarma int `json:"comment_karma"`
TotalKarma int `json:"total_karma"`
AwardeeKarma int `json:"awardee_karma,omitempty"`
AwarderKarma int `json:"awarder_karma,omitempty"`
Description string `json:"description,omitempty"`
DisplayTitle string `json:"display_title,omitempty"`
Followers int `json:"followers,omitempty"`
IconImg string `json:"icon_img,omitempty"`
IsGold bool `json:"is_gold,omitempty"`
IsMod bool `json:"is_mod,omitempty"`
IsEmployee bool `json:"is_employee,omitempty"`
Verified bool `json:"verified,omitempty"`
HasVerifiedEmail bool `json:"has_verified_email,omitempty"`
NSFW bool `json:"nsfw,omitempty"`
IsFriend bool `json:"is_friend,omitempty"`
IsBlocked bool `json:"is_blocked,omitempty"`
IsSuspended bool `json:"is_suspended,omitempty"`
InboxCount int `json:"inbox_count,omitempty"`
HasMail bool `json:"has_mail,omitempty"`
}
type WriteError ¶
type WriteError struct {
Errors [][]string
}
WriteError is Reddit rejecting a write on its own terms, such as a rate limit or a missing subreddit. The HTTP status is still 200 in that case.
func (*WriteError) Code ¶
func (e *WriteError) Code() string
Code returns the first error code Reddit gave, such as RATELIMIT.
func (*WriteError) Error ¶
func (e *WriteError) Error() string