Help us shape the future of Go! Take the 2026 Go Developer Survey

github

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package github is a small GitHub Contents API client that lists the ebuild versions a repository holds for a package, with an on-disk response cache, rate-limit detection and a token resolved from the secrets chain.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRateLimit indicates GitHub API rate limit exceeded
	ErrRateLimit = errors.New("GitHub API rate limit exceeded")
	// ErrNotFound indicates the requested resource was not found
	ErrNotFound = errors.New("package not found in repository")
	// ErrAPIError indicates a general GitHub API error
	ErrAPIError = errors.New("GitHub API error")
	// ErrUnauthorized indicates GitHub rejected the token (HTTP 401). An
	// error carrying it also matches ErrAPIError.
	ErrUnauthorized = errors.New("GitHub authentication rejected")
)

Functions

func ResolveToken

func ResolveToken() (string, error)

ResolveToken resolves a GitHub API token through the unified secrets chain, honouring GITHUB_TOKEN first then GH_TOKEN (the gh CLI convention). It returns ("", nil) when neither is set — anonymous access is allowed. A present-but- unreadable secrets file returns a non-nil error wrapping secrets.ErrUnreadable so a caller can warn rather than silently degrade to anonymous requests. This is the single source of truth for GitHub-token resolution.

Types

type CacheEntry

type CacheEntry struct {
	Versions  []string  `json:"versions"`
	Timestamp time.Time `json:"timestamp"`
}

CacheEntry represents a cached API response

type Client

type Client struct {
	BaseURL    string
	Repository string
	UserAgent  string
	Token      string // GitHub personal access token (optional, increases rate limit)
	HTTPClient *http.Client
	CacheDir   string
	CacheTTL   time.Duration
}

Client handles communication with the GitHub API

func NewClient

func NewClient() *Client

NewClient creates a new GitHub API client

func NewClientWithOptions

func NewClientWithOptions(repository string, cacheDir string, timeout time.Duration) *Client

NewClientWithOptions creates a new GitHub API client with custom options

func (*Client) ClearCache

func (c *Client) ClearCache() error

ClearCache removes all cached data

func (*Client) GetPackageVersions

func (c *Client) GetPackageVersions(ctx context.Context, category, pkg string) ([]string, error)

GetPackageVersions fetches all ebuild versions for a package from GitHub

func (*Client) GetRateLimitInfo

func (c *Client) GetRateLimitInfo(ctx context.Context) (remaining int, resetTime time.Time, err error)

GetRateLimitInfo returns current rate limit status. The request is bound to ctx: cancelling it aborts the lookup in flight, and the returned error wraps ctx.Err().

func (*Client) SetCacheDir

func (c *Client) SetCacheDir(dir string) error

SetCacheDir sets the cache directory for API responses

type ContentEntry

type ContentEntry struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Type        string `json:"type"` // "file" or "dir"
	DownloadURL string `json:"download_url,omitempty"`
}

ContentEntry represents a file/directory entry from GitHub Contents API

Jump to

Keyboard shortcuts

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