modrinth

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Example

Basic usage

package main

import (
	"context"
	"fmt"

	"github.com/minepkg/minepkg/internals/modrinth"
)

func main() {
	client := modrinth.New(nil)

	// Get the latest version of the fabric mod.
	versions, err := client.ListProjectVersion(context.Background(), "fabric-api", nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(versions[0].ProjectID)
}
Output:

P7dR8mSH

Index

Examples

Constants

View Source
const DefaultApiURL = "https://api.modrinth.com/"

Variables

View Source
var (
	// An error that is returned if the provided project ID or slug is invalid
	// currently this is only returned if it was an empty string
	ErrInvalidProjectIDOrSlug = errors.New("invalid project ID or slug")
	// An error that is returned if the provided version ID is invalid
	// currently this is only returned if it was an empty string
	ErrInvalidVersionID = errors.New("invalid version ID")
	// A generic error that is returned if a resource was not found
	// Some methods return more specific errors that wrap this error (e.g. ErrProjectNotFound)
	ErrResourceNotFound = errors.New("resource not found")
)
View Source
var (
	// ErrInvalidFileHash is returned when the hash is not a valid sha1 hash
	ErrInvalidFileHash = errors.New("invalid file hash")
)
View Source
var (
	ErrProjectNotFound = errors.Wrap(ErrResourceNotFound, "project not found")
)
View Source
var (
	// Is returned when a version is not found
	ErrVersionNotFound = errors.Wrap(ErrResourceNotFound, "version not found")
)

Functions

This section is empty.

Types

type Client

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

func New

func New(httpClient *http.Client) *Client

func (*Client) GetProject added in v0.1.13

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

GetProject returns the project with the given ID

func (*Client) GetVersion

func (c *Client) GetVersion(ctx context.Context, id string) (*Version, error)

GetVersion returns a single version for a project given a 6 char id (`IIJJKKLL`)

Example
package main

import (
	"context"
	"fmt"

	"github.com/minepkg/minepkg/internals/modrinth"
)

func main() {
	client := modrinth.New(nil)

	// get one version by its id
	version, err := client.GetVersion(context.Background(), "4XRtXhtL")
	if err != nil {
		panic(err)
	}
	fmt.Println(version.ProjectID)
}
Output:

P7dR8mSH

func (*Client) GetVersionFile

func (c *Client) GetVersionFile(ctx context.Context, hash string) (*Version, error)

GetVersionFile returns the version containing the file with the given hash. `hash` can be a sha1 or sha512 hash Caution: returns a `Version`, not a `File`

Example
package main

import (
	"context"
	"fmt"

	"github.com/minepkg/minepkg/internals/modrinth"
)

func main() {
	client := modrinth.New(nil)

	// get version with file hash
	version, err := client.GetVersionFile(
		context.Background(),
		"b9ab9ab267f8cdff525f9a8edb26435d3e2455f6",
	)

	if err != nil {
		panic(err)
	}

	fmt.Println(version.ID)
}
Output:

4XRtXhtL

func (*Client) ListProjectVersion

func (c *Client) ListProjectVersion(ctx context.Context, idOrSlug string, query *ListProjectVersionQuery) ([]Version, error)

ListProjectVersion returns a list of versions for a project. `query` can be used to pre filter the results. Pass nil to not filter.

type Dependency

type Dependency struct {
	VersionID      string      `json:"version_id"`
	ProjectID      string      `json:"project_id"`
	FileName       interface{} `json:"file_name"`
	DependencyType string      `json:"dependency_type"`
}

type File

type File struct {
	Hashes struct {
		Sha512 string `json:"sha512"`
		Sha1   string `json:"sha1"`
	} `json:"hashes"`
	URL      string `json:"url"`
	Filename string `json:"filename"`
	Primary  bool   `json:"primary"`
	Size     int    `json:"size"`
}

type ListProjectVersionQuery

type ListProjectVersionQuery struct {
	// Loaders is a list of loaders to filter by (e.g. "fabric", "forge", "quilt")
	Loaders []string `json:"loaders,omitempty"`
	// GameVersions is a list of Minecraft versions to filter by (e.g. "1.16.5", "1.17.1")
	GameVersions []string `json:"game_versions,omitempty"`
	// Featured is a boolean to filter by versions that are marked as "featured".
	// You'll need to pass in a reference if you want to include this field in the api request.
	// You can use the [ListProjectVersionQuery.SetFeatured] method to easily do this.
	Featured *bool `json:"featured,omitempty"`
}

ListProjectVersionQuery is used to filter the results of ListProjectVersion

func (*ListProjectVersionQuery) SetFeatured added in v0.1.23

func (l *ListProjectVersionQuery) SetFeatured(featured bool) *ListProjectVersionQuery

func (*ListProjectVersionQuery) String added in v0.1.23

func (l *ListProjectVersionQuery) String() string

String converts this to a query string

type Project added in v0.1.13

type Project struct {
	ID               string      `json:"id"`
	Slug             string      `json:"slug"`
	ProjectType      string      `json:"project_type"`
	Team             string      `json:"team"`
	Title            string      `json:"title"`
	Description      string      `json:"description"`
	Body             string      `json:"body"`
	BodyURL          interface{} `json:"body_url"`
	Published        time.Time   `json:"published"`
	Updated          time.Time   `json:"updated"`
	Approved         time.Time   `json:"approved"`
	Status           string      `json:"status"`
	ModeratorMessage struct {
		Message string      `json:"message"`
		Body    interface{} `json:"body"`
	} `json:"moderator_message"`
	License struct {
		ID   string `json:"id"`
		Name string `json:"name"`
		URL  string `json:"url"`
	} `json:"license"`
	ClientSide           string        `json:"client_side"`
	ServerSide           string        `json:"server_side"`
	Downloads            int           `json:"downloads"`
	Followers            int           `json:"followers"`
	Categories           []string      `json:"categories"`
	AdditionalCategories []interface{} `json:"additional_categories"`
	Versions             []string      `json:"versions"`
	IconURL              string        `json:"icon_url"`
	IssuesURL            string        `json:"issues_url"`
	SourceURL            string        `json:"source_url"`
	WikiURL              interface{}   `json:"wiki_url"`
	DiscordURL           string        `json:"discord_url"`
	DonationUrls         []interface{} `json:"donation_urls"`
	Gallery              []interface{} `json:"gallery"`
}

type Version

type Version struct {
	ID            string       `json:"id"`
	ProjectID     string       `json:"project_id"`
	AuthorID      string       `json:"author_id"`
	Featured      bool         `json:"featured"`
	Name          string       `json:"name"`
	VersionNumber string       `json:"version_number"`
	Changelog     string       `json:"changelog"`
	ChangelogURL  string       `json:"changelog_url"`
	DatePublished time.Time    `json:"date_published"`
	Downloads     int          `json:"downloads"`
	VersionType   string       `json:"version_type"`
	Files         []File       `json:"files"`
	Dependencies  []Dependency `json:"dependencies"`
	GameVersions  []string     `json:"game_versions"`
	Loaders       []string     `json:"loaders"`
}

Jump to

Keyboard shortcuts

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