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 ¶
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 ¶
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.
func (Type) 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.