versions

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package versions fetches Mojang's versions listing of Minecraft, allowing clients to determine what the latest version is.

This is useful to determine whether the latest version of the game is installed and/or construct download URLs for the latest versions of the game. For example:

vs, err := versions.Load(context.TODO())
if err != nil {
	log.Fatal("Failed to fetch versions listing: " + err.Error())
}

if latest := vs.Latest.Release; latest != currentVersion {
	url := fmt.Sprintf("http://s3.amazonaws.com/Minecraft.Download/versions/%s/%s.jar", latest, latest)
	resp, err := http.Get(url)
	...
}

For more information, see http://wiki.vg/Game_Files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listing

type Listing struct {
	Versions map[string]Version // Every known version of Minecraft, indexed by version ID.
	Latest   struct {
		Snapshot string // Version ID of the latest development snapshot.
		Release  string // Version ID of the latest Minecraft release.
	}
}

Listing is a listing of Minecraft versions.

func Load

func Load(ctx context.Context) (Listing, error)

Load fetches a listing of Minecraft versions from Mojang's servers. ctx must be non-nil. If an error occurs, a zero-value Listing will be returned. Load reports Mojang server communication failures using *url.Error.

Example

The following example demonstrates how to retrieve an updated listing of Minecraft releases and print information for select versions.

package main

import (
	"context"
	"log"

	"fmt"

	"github.com/PhilipBorgesen/minecraft/versions"
)

func main() {
	ctx := context.TODO()

	vs, err := versions.Load(ctx)
	if err != nil {
		log.Fatal("Failed to fetch versions listing: " + err.Error())
	}

	fmt.Println("VERSION    TYPE     RELEASE DATE")
	fmt.Println("-------------------------------------------------")
	for _, s := range []string{"1.8.1", "b1.0", "rd-132211"} {
		v := vs.Versions[s]
		fmt.Printf("%-9s  %-7s  %s\n", v.ID, v.Type, v.Released.UTC())
	}
}
Output:

VERSION    TYPE     RELEASE DATE
-------------------------------------------------
1.8.1      release  2014-11-24 14:13:31 +0000 UTC
b1.0       beta     2010-12-19 22:00:00 +0000 UTC
rd-132211  alpha    2009-05-13 20:11:00 +0000 UTC

func (Listing) LatestRelease

func (l Listing) LatestRelease() Version

LatestRelease returns the version information for the latest release version. It is the same as l.Versions[l.Latest.Release], except LatestRelease will panic if l.Versions doesn't contain the key l.Latest.Release.

type Type

type Type string

Type represents the release type of a version.

const (
	Release  Type = "release"   // Ordinary release
	Snapshot Type = "snapshot"  // Development snapshot
	Alpha    Type = "old_alpha" // An alpha version
	Beta     Type = "old_beta"  // A beta version
)

func (Type) String

func (t Type) String() string

String returns a description of the version type meant for humans:

Release.String()  = "release"
Snapshot.String() = "snapshot"
Alpha.String()    = "alpha"
Beta.String()     = "beta"
Type("").String() = "???" // Zero value

Users should not rely on the results of String for other version types than the ones specified above. The default description for an unknown Type X is string(X), but as future versions of this package becomes aware of new Mojang-introduced types, for the previous unknown Type A, A.String() may change to differ from string(A). Once String has been specified for a given Type A, the return value of A.String() won't change further.

type Version

type Version struct {
	ID       string    // Version identifier, e.g. "1.8.1".
	Released time.Time // When the version was released.
	Type     Type      // Type of release, e.g. ordinary release or development snapshot.
}

Version contains information about a Minecraft version. Version values should be used as map or database keys with caution as they contain a time.Time field. Using ID as the key alone is recommended. For the same reasons, do not use == with Version values; use Equal instead.

func (Version) Equal

func (v Version) Equal(u Version) bool

Equal reports whether v and u represents the same Minecraft version. For this to be true, v and u must have the same ID, be released at the same time instant, and be of the same release type. Do not use == with Version values.

func (Version) String

func (v Version) String() string

String returns v.ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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