modrinth

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-modrinth

Go


A client for the Modrinth API: search, project and version metadata, and file downloads. Package modrinth, module github.com/Rethunk-Tech/go-modrinth.

The package is the protocol half of a Modrinth client and holds no policy: it sends the request the API documents, decodes the answer into exported types, and stops. It guarantees three things on every call — the body is read at most once and at most 16 MiB, a redirect cannot leave the API's origin, and a non-2xx answer arrives as a *httpkit.StatusError the caller can match. It exists so that paging, batching, retrying and deciding which file to install stay with the program that knows the game.

Quick start

go get github.com/Rethunk-Tech/go-modrinth

A worked example and the contracts: HUMANS.md.

Features

  • Search projects by text and facets, ordered by relevance, downloads, follows, newest or updated, paged by offset.
  • Project metadata: title, summary, Markdown body, categories and moderation status.
  • One request for many projects, and one for many versions, batched by the caller at ProjectsBatch.
  • A project's versions filtered by loader and game version, and each version's primary file with its size, URL and SHA-1/SHA-512 digests.
  • Hash lookups: the versions that published a set of files, and the newest version each file should be updated to.
  • The category list, plus ValidID and PageURL for turning a user-supplied project id into a safe request or link.

Documentation

Doc Audience
HUMANS.md Running and using the package
AGENTS.md Internals, invariants, and why
CONTRIBUTING.md Process — commits, tests, docs
SECURITY.md Vulnerability disclosure
CHANGELOG.md Release notes

License

MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.

Documentation

Overview

Package modrinth is a client for the public Modrinth v2 API: search, projects, versions, files with their digests, dependencies and categories.

Index

Constants

View Source
const (
	// BaseURL is the Modrinth API root.
	BaseURL = "https://api.modrinth.com/v2"
	// MaxPageSize is the search API's largest limit.
	MaxPageSize = 100
	// ProjectsBatch is how many ids one Projects, Versions or VersionsByHash call should name.
	ProjectsBatch = 100
)
View Source
const (
	// IndexRelevance ranks by Modrinth's own relevance score, the API's default.
	IndexRelevance = "relevance"
	// IndexDownloads ranks by total downloads.
	IndexDownloads = "downloads"
	// IndexFollows ranks by follower count.
	IndexFollows = "follows"
	// IndexNewest ranks by first publication.
	IndexNewest = "newest"
	// IndexUpdated ranks by last modification.
	IndexUpdated = "updated"
)

Index orders a search result; SearchQuery.Index takes one.

Variables

This section is empty.

Functions

func PageURL

func PageURL(projectType, slug string) string

PageURL is the project's page address; projectType is the URL segment such as "mod" or "modpack", and slug is the project's slug or id.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a project id or slug, so it is safe to put in a request path.

Types

type Category

type Category struct {
	Name string `json:"name"`
	// ProjectType is the kind of project the category groups, such as "mod" or "modpack".
	ProjectType string `json:"project_type"`
}

Category is one project category tag, such as "fabric" or "adventure".

type Client

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

Client calls the Modrinth API. It holds no state beyond its configuration, so it is safe for concurrent use.

func New

func New(cfg Config) *Client

New builds a Client.

func (*Client) Categories

func (c *Client) Categories(ctx context.Context) ([]Category, error)

Categories lists the site's project categories across project types.

func (*Client) LatestByHash

func (c *Client) LatestByHash(ctx context.Context, algorithm string, hashes, loaders, gameVersions []string) (map[string]Version, error)

LatestByHash finds the newest version of each file that matches the loaders and game versions, keyed by the hash given. A file with no newer version is absent from the map.

func (*Client) Project

func (c *Client) Project(ctx context.Context, idOrSlug string) (Project, error)

Project reads one project by id or slug.

func (*Client) ProjectVersions

func (c *Client) ProjectVersions(ctx context.Context, project string, loaders, gameVersions []string) ([]Version, error)

ProjectVersions lists a project's versions, newest first, kept to loaders and game versions when either is named.

func (*Client) Projects

func (c *Client) Projects(ctx context.Context, ids []string) ([]Project, error)

Projects reads many projects in one request; name at most ProjectsBatch ids.

func (*Client) Search

func (c *Client) Search(ctx context.Context, q SearchQuery) (SearchResult, error)

Search lists projects matching q.

func (*Client) Versions

func (c *Client) Versions(ctx context.Context, ids []string) ([]Version, error)

Versions reads many versions by id in one request.

func (*Client) VersionsByHash

func (c *Client) VersionsByHash(ctx context.Context, algorithm string, hashes []string) (map[string]Version, error)

VersionsByHash reads the versions that published the given files, keyed by the hash given.

type Config

type Config struct {
	// BaseURL replaces the API root; empty means BaseURL.
	BaseURL string
	// HTTP sends every request; nil means a client with httpkit's default timeout. A redirect to another origin is
	// refused.
	HTTP *http.Client
	// UserAgent is sent with every request when set. Modrinth asks every client to identify itself.
	UserAgent string
}

Config is what a Client is built from.

type Dependency

type Dependency struct {
	ProjectID string `json:"project_id"`
	VersionID string `json:"version_id"`
	Type      string `json:"dependency_type"`
}

Dependency is a project a version builds on. Type is "required", "optional", "incompatible" or "embedded"; a required one names the project it needs and, when pinned, the version.

type File

type File struct {
	URL      string `json:"url"`
	Filename string `json:"filename"`
	Size     int64  `json:"size"`
	// Hashes is keyed by algorithm, "sha1" and "sha512" among them; a missing algorithm is absent.
	Hashes  map[string]string `json:"hashes"`
	Primary bool              `json:"primary"`
}

File is one downloadable file of a version.

type Project

type Project struct {
	ID          string `json:"id"`
	Slug        string `json:"slug"`
	Title       string `json:"title"`
	Description string `json:"description"`
	// Body is the project's page in Markdown.
	Body       string   `json:"body"`
	Categories []string `json:"categories"`
	// AdditionalCategories are the ones the project picks beyond its type's primary list.
	AdditionalCategories []string `json:"additional_categories"`
	// Status is the project's moderation state; "archived" means the author has retired it.
	Status string `json:"status"`
}

Project is one Modrinth project as the API describes it.

type SearchHit

type SearchHit struct {
	ProjectID   string `json:"project_id"`
	Slug        string `json:"slug"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Author      string `json:"author"`
	IconURL     string `json:"icon_url"`
	Downloads   int    `json:"downloads"`
	Follows     int    `json:"follows"`
	// Modified is the project's last change, RFC 3339.
	Modified string `json:"date_modified"`
	// Versions are the ids of the project's versions, and Latest is the newest of them.
	Versions []string `json:"versions"`
	Latest   string   `json:"latest_version"`
}

SearchHit is one project in a search answer.

type SearchQuery

type SearchQuery struct {
	// Text matches project names, summaries and descriptions.
	Text string
	// Facets keeps only projects matching every group, and the strings inside one group are alternatives, as in
	// [][]string{{"categories:fabric", "categories:quilt"}}.
	Facets [][]string
	// Index is one of the Index constants; empty means IndexRelevance.
	Index string
	// Offset is the first hit's position and Limit the page length, at most MaxPageSize; zero Limit is MaxPageSize.
	Offset, Limit int
}

SearchQuery is one search. Zero fields keep the API's defaults: no text, no facet filter, relevance order and the first page.

type SearchResult

type SearchResult struct {
	// Total is the number of matching projects, not the number of hits.
	Total int         `json:"total_hits"`
	Hits  []SearchHit `json:"hits"`
}

SearchResult is one page of search hits.

type Version

type Version struct {
	ID            string       `json:"id"`
	ProjectID     string       `json:"project_id"`
	VersionNumber string       `json:"version_number"`
	DatePublished string       `json:"date_published"`
	Files         []File       `json:"files"`
	Dependencies  []Dependency `json:"dependencies"`
}

Version is one published build of a project.

func (Version) PrimaryFile

func (v Version) PrimaryFile() (File, bool)

PrimaryFile is the version's primary file, else its first; ok is false when it has none.

Jump to

Keyboard shortcuts

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