mojang

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mojang is the library behind the mojang command line: the HTTP client, request shaping, and the typed data models for the Mojang API (https://api.mojang.com).

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx). All public Mojang endpoints are unauthenticated: no API key is required.

Index

Constants

View Source
const BaseURL = "https://api.mojang.com"

BaseURL is the root for player UUID lookups.

View Source
const DefaultUserAgent = "mojang-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to Mojang.

View Source
const Host = "api.mojang.com"

Host is the primary API hostname used for URI routing.

View Source
const SessionURL = "https://sessionserver.mojang.com"

SessionURL is the root for full profile (skin/cape) lookups.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP       *http.Client
	UserAgent  string
	BaseURL    string
	SessionURL string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the Mojang API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 15s timeout, a 500ms minimum gap between requests (Mojang rate-limits aggressively), and 3 retries.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the response body. It paces and retries according to the client's settings. The caller owns the returned slice.

func (*Client) GetProfile

func (c *Client) GetProfile(ctx context.Context, username string) (*Profile, error)

GetProfile fetches the full player profile for username: first resolves the UUID, then fetches skin/cape data from the session server. If the session call fails, the UUID result is still returned with SkinURL empty.

func (*Client) GetUUID

func (c *Client) GetUUID(ctx context.Context, username string) (*Profile, error)

GetUUID resolves a Minecraft username to its UUID (single API call). SkinURL is always empty on the returned Profile.

type Domain

type Domain struct{}

Domain is the mojang driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input (a Minecraft username or UUID) into the canonical (type, id) pair, so `ant resolve` and `ant url` touch no network.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Profile

type Profile struct {
	ID      string `json:"id"       kit:"id"  table:"id"`
	Name    string `json:"name"               table:"name"`
	SkinURL string `json:"skin_url,omitempty" table:"skin_url"`
}

Profile is the data model for a Minecraft player profile. It is returned by both the profile and uuid operations. SkinURL is populated only by the profile op (which makes a second call to the session server); the uuid op leaves it empty.

Jump to

Keyboard shortcuts

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