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 ¶
const BaseURL = "https://api.mojang.com"
BaseURL is the root for player UUID lookups.
const DefaultUserAgent = "mojang-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to Mojang.
const Host = "api.mojang.com"
Host is the primary API hostname used for URI routing.
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 ¶
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 ¶
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.
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 ¶
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.
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.