indexers

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuthError

func IsAuthError(err error) bool

Reports whether the error is an auth error

func IsNetworkError

func IsNetworkError(err error) bool

Reports whether the error is a network error

func IsNotFound

func IsNotFound(err error) bool

Reports whether the error is a not-found error

func IsRateLimit

func IsRateLimit(err error) bool

Reports whether the error is a rate-limit error

func RegisterIndexer

func RegisterIndexer(name string, factory IndexerFactory)

RegisterIndexer registers an IndexerFactory under the given name. Typically called from an indexer package's init() function.

Types

type ErrorKind

type ErrorKind int

indexer errors

const (
	ErrAuth      ErrorKind = iota // 401/403 or missing API key
	ErrRateLimit                  // 429
	ErrNotFound                   // 404
	ErrNetwork                    // DNS failure, timeout, connection refused
	ErrAPI                        // Other non-2xx status codes
	ErrDecode                     // JSON decode failures
)

func (ErrorKind) String

func (k ErrorKind) String() string

type HTTPClient

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

HTTPClient wraps http.Client with common indexer request logic.

func NewHTTPClient

func NewHTTPClient(indexer string, userAgent string, extraHeaders map[string]string) *HTTPClient

NewHTTPClient creates a shared HTTP client for an indexer.

func (*HTTPClient) DoJSON

func (h *HTTPClient) DoJSON(ctx context.Context, url string, dest any) error

DoJSON performs a GET request, checks the status, and JSON-decodes into dest. It returns structured IndexerErrors for all failure modes.

type IndexerError

type IndexerError struct {
	Kind       ErrorKind
	Indexer    string
	StatusCode int
	URL        string
	Body       string
	Err        error
}

func NewAPIError

func NewAPIError(indexer string, statusCode int, url string, body string) *IndexerError

It automatically classifies 401/403 as Auth, 404 as NotFound, 429 as RateLimit.

func NewAuthConfigError

func NewAuthConfigError(indexer string, msg string) *IndexerError

Missing API key configuration

func NewDecodeError

func NewDecodeError(indexer string, url string, err error) *IndexerError

JSON decode failures.

func NewNetworkError

func NewNetworkError(indexer string, url string, err error) *IndexerError

IndexerError for network-level failures like dns

func (*IndexerError) Error

func (e *IndexerError) Error() string

func (*IndexerError) Unwrap

func (e *IndexerError) Unwrap() error

type IndexerFactory

type IndexerFactory func(apiKey string, cfg *config.Config) ModpackIndexer

IndexerFactory creates a ModpackIndexer from an API key and config.

type Modpack

type Modpack struct {
	ID            string    `json:"id"`
	IndexerID     string    `json:"indexer_id"` // Original ID from the indexer
	Indexer       string    `json:"indexer"`    // Which indexer this came from
	Name          string    `json:"name"`
	Slug          string    `json:"slug"`
	Summary       string    `json:"summary"`
	Description   string    `json:"description"`
	LogoURL       string    `json:"logo_url"`
	WebsiteURL    string    `json:"website_url"`
	DownloadCount int64     `json:"download_count"`
	Categories    []string  `json:"categories"`
	GameVersions  []string  `json:"game_versions"`
	ModLoaders    []string  `json:"mod_loaders"`
	LatestFileID  string    `json:"latest_file_id"`
	DateCreated   time.Time `json:"date_created"`
	DateModified  time.Time `json:"date_modified"`
	DateReleased  time.Time `json:"date_released"`
}

Modpack represents a modpack from any indexer

type ModpackFile

type ModpackFile struct {
	ID               string    `json:"id"`
	ModpackID        string    `json:"modpack_id"`
	DisplayName      string    `json:"display_name"`
	FileName         string    `json:"file_name"`
	FileDate         time.Time `json:"file_date"`
	FileLength       int64     `json:"file_length"`
	ReleaseType      string    `json:"release_type"` // "release", "beta", "alpha"
	DownloadURL      string    `json:"download_url"`
	GameVersions     []string  `json:"game_versions"`
	ModLoader        string    `json:"mod_loader"`
	ServerPackFileID *string   `json:"server_pack_file_id,omitempty"`
	SortIndex        int       `json:"sort_index"`
	VersionNumber    string    `json:"version_number"` // Human-readable version for Modrinth
}

ModpackFile represents a downloadable file for a modpack

type ModpackIndexer

type ModpackIndexer interface {
	// SearchModpacks searches for modpacks with the given criteria
	SearchModpacks(ctx context.Context, query string, gameVersion string, modLoader string, offset, limit int) (*SearchResult, error)

	// GetModpack retrieves detailed information about a specific modpack
	GetModpack(ctx context.Context, modpackID string) (*Modpack, error)

	// GetModpackFiles retrieves all available files for a modpack
	GetModpackFiles(ctx context.Context, modpackID string) ([]ModpackFile, error)

	// GetIndexerName returns the name of this indexer (e.g., "fuego", "modrinth")
	GetIndexerName() string
}

ModpackIndexer defines the interface for modpack indexing services

func NewIndexer

func NewIndexer(name string, apiKey string, cfg *config.Config) (ModpackIndexer, error)

NewIndexer creates a ModpackIndexer by name using the factory registry.

type SearchResult

type SearchResult struct {
	Modpacks   []Modpack
	TotalCount int
	PageSize   int
	Offset     int
}

SearchResult contains the results of a modpack search

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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