stackoverflow

package
v0.26.15 Latest Latest
Warning

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

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

Documentation

Overview

Package stackoverflow wraps the public Stack Exchange Data API (api.stackexchange.com) to surface a contributor's Stack Overflow reputation as a cross-platform credibility signal. Discovery flow: the contributor's GitHub profile (bio or blog) declares a stackoverflow.com/users/{id}/{slug} link → we extract the user ID → the SE API returns reputation, badges, and account metadata.

SE rate limits: 300 requests/day per IP unauthenticated, 10000/day when a registered `key` is provided. Weekly cache keeps us comfortably under either ceiling.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("stackoverflow: user not found")

ErrNotFound is returned when the SE API has no user with the requested ID. Distinguishes "user does not exist" from a transport or decode error so callers can cache the empty result.

Functions

func ExtractUserID

func ExtractUserID(rawURL string) int64

ExtractUserID returns the Stack Overflow user ID encoded in the given URL, or 0 if the URL is not a recognizable SO profile link. Used by the service layer to convert a contributor's classified stackoverflow LinkedAccount into an API lookup.

Types

type Client

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

Client is the Stack Overflow / Stack Exchange API client.

func NewClient

func NewClient(timeout time.Duration, apiKey string) *Client

NewClient returns a Client with the given timeout and optional API key. A zero or negative timeout falls back to a sane default; an empty apiKey runs against the unauthenticated quota.

func (*Client) FetchUser

func (c *Client) FetchUser(ctx context.Context, userID int64) (*Profile, error)

FetchUser retrieves the SE user identified by the numeric ID on the Stack Overflow site. Returns ErrNotFound when the API returns an empty `items` list (the SE API responds 200 even for missing users; the empty list is the not-found signal).

type Profile

type Profile struct {
	UserID       int64
	DisplayName  string
	Reputation   int64
	BadgeBronze  int
	BadgeSilver  int
	BadgeGold    int
	URL          string
	CreatedAt    time.Time
	LastAccessAt time.Time
}

Profile is the parsed SE user response. Only fields we surface are kept; the SE API returns considerably more (collectives, per-period reputation deltas, accept rate) that we currently do not display.

Jump to

Keyboard shortcuts

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