core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 35 Imported by: 1 module, 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.

Documentation

Index

Constants

View Source
const (
	ModeURL string = "url"
	ModeCF  string = "metadata:curseforge"
)
View Source
const (
	ServerSide    = "server"
	ClientSide    = "client"
	UniversalSide = "both"
	EmptySide     = ""
)

The four possible values of Side (the side that the mod is on) are "server", "client", "both", and "" (equivalent to "both")

View Source
const CurrentPackFormat = "packwiz:1.1.0"
View Source
const DownloadCacheImportFolder = "import"
View Source
const MRPackOverrideStorageDir = ".packwiz-mrpack"

MRPackOverrideStorageDir holds Modrinth-specific override layers for re-export.

View Source
const MetaExtension = ".pw.toml"

MetaExtension is the file extension of the mod metadata files Note that this is currently not required; it will only be used for new files.

View Source
const MetaExtensionOld = ".toml"
View Source
const UserAgent = "packwiz/packwiz"

Variables

View Source
var MetaDownloaders = make(map[string]MetaDownloader)

MetaDownloaders stores all the metadata-based installers that packwiz can use. Add your own downloaders to this map, keyed by the source name.

View Source
var ModLoaders = createModloaderMap(modLoadersList)

A map containing information about all supported modloaders. Can be indexed by the ModLoaderComponent's name, which serves as an identifier.

View Source
var PackFormatConstraintAccepted = mustParseConstraint("~1")
View Source
var PackFormatConstraintSuggestUpgrade = mustParseConstraint("~1.1")
View Source
var PlatformLinkers = make(map[string]func(FileIdentity, string) (map[string]any, error))

PlatformLinkers are registered by each platform to avoid package cycles. An empty reference requests detection; a URL restricts it to that project/file.

View Source
var Updaters = make(map[string]Updater)

Updaters stores all the updaters that packwiz can use. Add your own update systems to this map, keyed by the configuration name.

Functions

func AutoLinkMod added in v0.2.0

func AutoLinkMod(m *Mod)

AutoLinkMod never fails the primary installation/update.

func ComponentToFriendlyName

func ComponentToFriendlyName(component string) string

func GetAPIWithUA added in v0.2.0

func GetAPIWithUA(url string, contentType string) (resp *http.Response, err error)

GetAPIWithUA bounds small metadata/API requests. Downloads use GetWithUA so large mod files can stream without a total request timeout.

func GetPackwizCache

func GetPackwizCache() (string, error)

func GetPackwizInstallBinFile

func GetPackwizInstallBinFile() (string, error)

func GetPackwizInstallBinPath

func GetPackwizInstallBinPath() (string, error)

func GetPackwizLocalCache

func GetPackwizLocalCache() (string, error)

func GetPackwizLocalStore

func GetPackwizLocalStore() (string, error)

func GetWithUA

func GetWithUA(url string, contentType string) (resp *http.Response, err error)

func HighestSliceIndex

func HighestSliceIndex(slice []string, values []string) int

HighestSliceIndex returns the highest index of the given values in the slice (-1 if no value is found in the slice)

func LinkMod added in v0.2.0

func LinkMod(m *Mod, target, reference string) error

func ReencodeURL

func ReencodeURL(u string) (string, error)

ReencodeURL re-encodes URLs for RFC3986 compliance; as CurseForge URLs aren't properly encoded

func ResetSecondaryReferences added in v0.2.0

func ResetSecondaryReferences(m *Mod, source string)

ResetSecondaryReferences must run only after a successful primary update.

func SlugifyName

func SlugifyName(name string) string

func ValidatePlatformReferences added in v0.2.0

func ValidatePlatformReferences(mods []*Mod, target string, allowOverrides bool) error

func WriteInstalledMod added in v0.2.0

func WriteInstalledMod(mod *Mod, index *Index) error

WriteInstalledMod reuses an existing project's path even when platform slugs differ, and keeps user options instead of replacing them with defaults. ponytail: one index scan per add; build a project lookup if large dependency batches make this O(n²) work measurable.

Types

type CacheIndex

type CacheIndex struct {
	Version uint32
	Hashes  map[string][]string
	// contains filtered or unexported fields
}

func (*CacheIndex) GetHandleFromHash

func (c *CacheIndex) GetHandleFromHash(hashFormat string, hash string) *CacheIndexHandle

func (*CacheIndex) GetHandleFromHashForce

func (c *CacheIndex) GetHandleFromHashForce(hashFormat string, hash string) (*CacheIndexHandle, error)

GetHandleFromHashForce looks up the given hash in the index; but will rehash any file without this hash format to obtain the necessary hash. Only use this for manually downloaded files, as it can rehash every file in the cache, which can be more time-consuming than just redownloading the file and noticing it is already in the index!

func (*CacheIndex) MoveImportFiles

func (c *CacheIndex) MoveImportFiles() error

func (*CacheIndex) NewHandleFromHashes

func (c *CacheIndex) NewHandleFromHashes(hashes map[string]string) (*CacheIndexHandle, bool)

type CacheIndexHandle

type CacheIndexHandle struct {
	Hashes map[string]string
	// contains filtered or unexported fields
}

func (*CacheIndexHandle) CreateFromTemp

func (h *CacheIndexHandle) CreateFromTemp(temp *os.File) (*os.File, error)

func (*CacheIndexHandle) GetRemainingHashes

func (h *CacheIndexHandle) GetRemainingHashes(hashesToObtain []string) []string

func (*CacheIndexHandle) Open

func (h *CacheIndexHandle) Open() (*os.File, error)

func (*CacheIndexHandle) Path

func (h *CacheIndexHandle) Path() string

func (*CacheIndexHandle) Remove

func (h *CacheIndexHandle) Remove()

func (*CacheIndexHandle) UpdateIndex

func (h *CacheIndexHandle) UpdateIndex() (warnings []error)

type CompletedDownload

type CompletedDownload struct {
	// File is only populated when the download is successful; points to the opened cache file
	File *os.File
	Mod  *Mod
	// Hashes is only populated when the download is successful; contains all stored hashes of the file
	Hashes map[string]string
	// Error indicates if/why downloading this file failed
	Error error
	// Warnings indicates messages to show to the user regarding this file (download was successful, but had a problem)
	Warnings []error
}

type DownloadSession

type DownloadSession interface {
	GetManualDownloads() []ManualDownload
	StartDownloads() chan CompletedDownload
	SaveIndex() error
}

func CreateDownloadSession

func CreateDownloadSession(mods []*Mod, hashesToObtain []string) (DownloadSession, error)

type FileIdentity added in v0.2.0

type FileIdentity struct {
	// ponytail: one artifact in memory for CF fingerprints; stream normalization
	// if unusually large artifacts make memory pressure measurable.
	Bytes  []byte
	Hashes map[string]string
}

FileIdentity is computed from the installed artifact, not its name/version.

func ReadFileIdentity added in v0.2.0

func ReadFileIdentity(m *Mod) (FileIdentity, error)

ReadFileIdentity reuses the download cache and its integrity checks.

type ForgeRecommended

type ForgeRecommended struct {
	Homepage string            `json:"homepage"`
	Versions map[string]string `json:"promos"`
}

type HashStringer

type HashStringer interface {
	hash.Hash
	HashToString([]byte) string
}

func GetHashImpl

func GetHashImpl(hashType string) (HashStringer, error)

GetHashImpl gets an implementation of hash.Hash for the given hash type string

type Index

type Index struct {
	HashFormat string
	Files      IndexFiles
	// contains filtered or unexported fields
}

Index is a representation of the index.toml file for referencing all the files in a pack.

func LoadIndex

func LoadIndex(indexFile string) (Index, error)

LoadIndex attempts to load the index file from a path

func (Index) FindMod

func (in Index) FindMod(modName string) (string, bool)

FindMod finds a mod in the index and returns its path and whether it has been found

func (Index) LoadAllMods

func (in Index) LoadAllMods() ([]*Mod, error)

LoadAllMods reads all metadata files into Mod structs

func (*Index) Refresh

func (in *Index) Refresh() error

Refresh updates the hashes of all the files in the index, and adds new files to the index

func (*Index) RefreshFileWithHash

func (in *Index) RefreshFileWithHash(path, format, hash string, markAsMetaFile bool) error

RefreshFileWithHash updates a file in the index, given a file hash and whether it should be marked as metafile or not

func (Index) RelIndexPath

func (in Index) RelIndexPath(p string) (string, error)

RelIndexPath turns a file path on disk into a path from the index

func (*Index) RemoveFile

func (in *Index) RemoveFile(path string) error

RemoveFile removes a file from the index, given a file path

func (Index) ResolveIndexPath

func (in Index) ResolveIndexPath(p string) string

ResolveIndexPath turns a path from the index into a file path on disk

func (Index) Write

func (in Index) Write() error

Write saves the index file

type IndexFiles

type IndexFiles map[string]IndexPathHolder

IndexFiles are stored as a map of path -> (indexFile or alias -> indexFile) The latter is used for multiple copies with the same path but different alias

type IndexPathHolder

type IndexPathHolder interface {
	IsMetaFile() bool
	// Returns all aliases, or File when no alias is set.
	AliasPaths() []string
	// contains filtered or unexported methods
}

type LengthHasher

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

func (*LengthHasher) BlockSize

func (h *LengthHasher) BlockSize() int

func (*LengthHasher) Reset

func (h *LengthHasher) Reset()

func (*LengthHasher) Size

func (h *LengthHasher) Size() int

func (*LengthHasher) Sum

func (h *LengthHasher) Sum(b []byte) []byte

func (*LengthHasher) Write

func (h *LengthHasher) Write(p []byte) (n int, err error)

type ManualDownload

type ManualDownload struct {
	Name     string
	FileName string
	URL      string
}

type MavenMetadata

type MavenMetadata struct {
	XMLName    xml.Name `xml:"metadata"`
	GroupID    string   `xml:"groupId"`
	ArtifactID string   `xml:"artifactId"`
	Versioning struct {
		Release  string `xml:"release"`
		Latest   string `xml:"latest"`
		Versions struct {
			Version []string `xml:"version"`
		} `xml:"versions"`
		LastUpdated string `xml:"lastUpdated"`
	} `xml:"versioning"`
}

type MetaDownloader

type MetaDownloader interface {
	GetFilesMetadata([]*Mod) ([]MetaDownloaderData, error)
}

MetaDownloader specifies a downloader for a Mod using a "metadata:source" mode The calling code should handle caching and hash validation.

type MetaDownloaderData

type MetaDownloaderData interface {
	GetManualDownload() (bool, ManualDownload)
	DownloadFile() (io.ReadCloser, error)
}

MetaDownloaderData specifies the per-Mod metadata retrieved for downloading

type Mod

type Mod struct {
	Name         string          `toml:"name"`
	FileName     string          `toml:"filename"`
	Side         string          `toml:"side,omitempty"`
	Environment  *ModEnvironment `toml:"environment,omitempty"`
	Pin          bool            `toml:"pin,omitempty"`
	UpdateSource string          `toml:"update-source,omitempty"`
	Download     ModDownload     `toml:"download"`
	// Update is a map of map of stuff, so you can store arbitrary values on string keys to define updating
	Update map[string]map[string]any `toml:"update"`

	Option *ModOption `toml:"option,omitempty"`
	// contains filtered or unexported fields
}

Mod stores metadata about a mod. This is written to a TOML file for each mod.

func LoadMod

func LoadMod(modFile string) (Mod, error)

LoadMod attempts to load a mod file from a path

func (Mod) GetDestFilePath

func (m Mod) GetDestFilePath() string

GetDestFilePath returns the path of the destination file of the mod

func (Mod) GetFilePath

func (m Mod) GetFilePath() string

GetFilePath is a clumsy hack that I made because Mod already stores it's path anyway

func (Mod) GetParsedUpdateData

func (m Mod) GetParsedUpdateData(updaterName string) (any, bool)

GetParsedUpdateData can be used to retrieve updater-specific information after parsing a mod file

func (*Mod) ParseUpdateData added in v0.2.0

func (mod *Mod) ParseUpdateData() error

ParseUpdateData refreshes parsed metadata after an in-memory update or link.

func (Mod) PrimaryUpdateSource added in v0.2.0

func (m Mod) PrimaryUpdateSource() (string, error)

func (*Mod) SetMetaPath

func (m *Mod) SetMetaPath(metaFile string) string

SetMetaPath sets the file path of a metadata file

func (Mod) Write

func (m Mod) Write() (string, string, error)

Write saves the mod file, returning a hash format and the value of the hash of the saved file

type ModDownload

type ModDownload struct {
	URL        string `toml:"url,omitempty"`
	HashFormat string `toml:"hash-format"`
	Hash       string `toml:"hash"`
	// Mode defaults to modeURL (i.e. use URL when omitted or empty)
	Mode string `toml:"mode,omitempty"`
}

ModDownload specifies how to download the mod file

type ModEnvironment added in v0.2.0

type ModEnvironment struct {
	Client string `toml:"client" json:"client"`
	Server string `toml:"server" json:"server"`
}

ModEnvironment stores exact client/server environment requirements for formats that can express different requirements on each side.

type ModLoaderComponent

type ModLoaderComponent struct {
	// An identifier for the modloader
	Name string
	// A user-friendly name
	FriendlyName string
	// Retrieves the list of all modloader versions. Modloader versions are always filtered to those compatible
	// with a specific minecraft version.
	VersionListGetter func(q VersionListQuery) (*ModLoaderVersions, error)
}

type ModLoaderVersions

type ModLoaderVersions struct {
	// All Versions of this modloader
	Versions []string
	// The Latest/preferred version for this modloader
	Latest string
}

func DoQuery

Queries the versions of a modloader

type ModOption

type ModOption struct {
	Optional    bool   `toml:"optional"`
	Description string `toml:"description,omitempty"`
	Default     bool   `toml:"default,omitempty"`
}

ModOption specifies optional metadata for this mod file

type Pack

type Pack struct {
	Name        string `toml:"name"`
	Author      string `toml:"author,omitempty"`
	Version     string `toml:"version,omitempty"`
	Description string `toml:"description,omitempty"`
	PackFormat  string `toml:"pack-format"`
	Index       struct {
		// Path is stored in forward slash format relative to pack.toml
		File       string `toml:"file"`
		HashFormat string `toml:"hash-format"`
		Hash       string `toml:"hash,omitempty"`
	} `toml:"index"`
	Versions map[string]string         `toml:"versions"`
	Export   map[string]map[string]any `toml:"export"`
	Options  map[string]any            `toml:"options"`
}

Pack stores the modpack metadata, usually in pack.toml

func LoadPack

func LoadPack() (Pack, error)

LoadPack loads the modpack metadata to a Pack struct

func (Pack) CreateExportFile

func (pack Pack) CreateExportFile(fileName string, defaultFileExt string) (*os.File, error)

func (Pack) GetCompatibleLoaders

func (pack Pack) GetCompatibleLoaders() (loaders []string)

func (Pack) GetLoaders

func (pack Pack) GetLoaders() (loaders []string)

func (Pack) GetMCVersion

func (pack Pack) GetMCVersion() (string, error)

GetMCVersion gets the version of Minecraft this pack uses, if it has been correctly specified

func (Pack) GetPackName

func (pack Pack) GetPackName() string

func (Pack) GetSlug

func (pack Pack) GetSlug() string

func (Pack) GetSupportedMCVersions

func (pack Pack) GetSupportedMCVersions() ([]string, error)

GetSupportedMCVersions gets the versions of Minecraft this pack allows in downloaded mods, ordered by preference (highest = most desirable)

func (Pack) LoadIndex

func (pack Pack) LoadIndex() (Index, error)

LoadIndex attempts to load the index file of this modpack

func (*Pack) UpdateIndexHash

func (pack *Pack) UpdateIndexHash() error

UpdateIndexHash recalculates the hash of the index file of this modpack

func (Pack) Write

func (pack Pack) Write() error

Write saves the pack file

func (Pack) WriteExportFile added in v0.2.0

func (pack Pack) WriteExportFile(fileName, defaultFileExt string, write func(io.Writer) error) (string, error)

WriteExportFile preserves existing output on every failure, not just preflight errors. It shares filename resolution with CreateExportFile.

type PlatformAuthError added in v0.2.0

type PlatformAuthError struct{ Platform string }

PlatformAuthError marks credentials rejected by a platform so batch linking can stop retrying the same permanent failure for every mod.

func (*PlatformAuthError) Error added in v0.2.0

func (e *PlatformAuthError) Error() string

type QueryType

type QueryType int
const (
	// The Latest field will contain the last released loader version
	Latest QueryType = iota
	// The Latest field will contain the loader version recommended for use
	Recommended
)

type UpdateCheck

type UpdateCheck struct {
	// UpdateAvailable is true if an update is available for this mod
	UpdateAvailable bool
	// UpdateString is a string that details the update in some way to the user. Usually this will be in the form of
	// a version change (1.0.0 -> 1.0.1), or a file name change (thanos-skin-1.0.0.jar -> thanos-skin-1.0.1.jar).
	UpdateString string
	// CachedState can be used to preserve per-mod state between CheckUpdate and DoUpdate (e.g. file metadata)
	CachedState any
	// Error stores an error for this specific mod
	// Errors can also be returned from CheckUpdate directly, if the whole operation failed completely (so only 1 error is printed)
	// If an error is returned for a mod, or from CheckUpdate, DoUpdate is not called on that mod / at all
	Error error
}

UpdateCheck represents the data returned from CheckUpdate for each mod

type Updater

type Updater interface {
	// ParseUpdate takes an unparsed interface{} (as a map[string]interface{}), and returns an Updater for a mod file.
	// This can be done using the mapstructure library or your own parsing methods.
	ParseUpdate(map[string]any) (any, error)
	// CheckUpdate checks whether there is an update for each of the mods in the given slice,
	// called for all of the mods that this updater handles
	CheckUpdate([]*Mod, Pack) ([]UpdateCheck, error)
	// DoUpdate carries out the update previously queried in CheckUpdate, on each Mod's metadata,
	// given pointers to Mods and the value of CachedState for each mod
	DoUpdate([]*Mod, []any) error
}

Updater is used to process updates on mods

type VersionListQuery

type VersionListQuery struct {
	// Which loader to query versions for
	Loader ModLoaderComponent
	// Which minecraft version the returned loader versions should be compatible with
	McVersion string
	// Determines how the latest version is determined
	QueryType QueryType
}

func MakeQuery

func MakeQuery(loader ModLoaderComponent, mcVersion string) VersionListQuery

func (VersionListQuery) WithQueryType

func (in VersionListQuery) WithQueryType(queryType QueryType) VersionListQuery

Jump to

Keyboard shortcuts

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