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
- func PageURL(projectType, slug string) string
- func ValidID(id string) bool
- type Category
- type Client
- func (c *Client) Categories(ctx context.Context) ([]Category, error)
- func (c *Client) LatestByHash(ctx context.Context, algorithm string, ...) (map[string]Version, error)
- func (c *Client) Project(ctx context.Context, idOrSlug string) (Project, error)
- func (c *Client) ProjectVersions(ctx context.Context, project string, loaders, gameVersions []string) ([]Version, error)
- func (c *Client) Projects(ctx context.Context, ids []string) ([]Project, error)
- func (c *Client) Search(ctx context.Context, q SearchQuery) (SearchResult, error)
- func (c *Client) Versions(ctx context.Context, ids []string) ([]Version, error)
- func (c *Client) VersionsByHash(ctx context.Context, algorithm string, hashes []string) (map[string]Version, error)
- type Config
- type Dependency
- type File
- type Project
- type SearchHit
- type SearchQuery
- type SearchResult
- type Version
Constants ¶
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 )
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 ¶
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 (*Client) Categories ¶
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, versionTypes []string) (map[string]Version, error)
LatestByHash finds the newest version of each file that matches the loaders, game versions and version types, keyed by the hash given. A file with no newer version is absent from the map.
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 ¶
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.
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 ¶
PrimaryFile is the version's primary file, else its first; ok is false when it has none.