releases

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package releases contains code that is related to Go SDK release detection and handling. It contains functions for receiving the all releases and ways to download them.

Index

Constants

View Source
const (

	// SourceFile describes the file kind source archiveutil of the Golang SDK release.
	SourceFile = FileKind("source")
	// ArchiveFile describes the file kind binary distribution archiveutil of the Golang SDK release.
	ArchiveFile = FileKind("archive")
	// InstallerFile describes the file kind installer executable of the Golang SDK release.
	InstallerFile = FileKind("installer")
)
View Source
const (

	// IncludeAll is the release type that will include each and every release of Go that was ever distributed publicly.
	IncludeAll = ReleaseType("all")
	// IncludeStable is the release type that will include each release that is currently considered stable.
	IncludeStable = ReleaseType("stable")
)

Variables

View Source
var (
	// ReleaseListCache is a map that caches the last fetched release list. Visible mostly for testing.
	ReleaseListCache = map[ReleaseType]Collection{}
)

Functions

This section is empty.

Types

type Collection

type Collection []*Release

The Collection type is a type-alias for a slice of releases, which also implements sort.Interface.

func ListAll

func ListAll(releaseType ReleaseType) (Collection, error)

ListAll is a function that retrieves a list of all Golang releases from the official website. This list is retrieved by querying a JSON endpoint that is provided by the official Golang website. If the endpoint responds with any other status code than 200, an error is returned.

func (Collection) Len

func (c Collection) Len() int

See sort.Interface for more details.

func (Collection) Less

func (c Collection) Less(i, j int) bool

See sort.Interface for more details.

func (Collection) Swap

func (c Collection) Swap(i, j int)

See sort.Interface for more details.

type FileKind

type FileKind string

The FileKind type is a string that describes what nature a ReleaseFile has.

type Release

type Release struct {
	// The version name of the release. It has the pattern of `go1.X.Y`.
	Version string `json:"version"`
	// Flag that marks a release as stable. A release is considered stable if it is one of the latest two releases and has
	// the latest patch version.
	Stable bool `json:"stable"`
	// A slice of all files that are associated with the release. This should never be empty.
	Files []ReleaseFile `json:"files"`
}

Release is a struct that holds all the relevant information about a released Go version. The official golang website offers a JSON-based endpoint that serves a list of all Golang releases that are structured just like this struct, so it can be used to read that endpoint.

func GetForVersion

func GetForVersion(releaseType ReleaseType, version *version.Version) (*Release, bool, error)

GetForVersion is a function that returns the Golang release with a given version, if such a release exists. A list of releases is retrieved, honoring the given release type as a filter, and then scanned for a release that has the same version number as the version variable. If no such release can be found, an empty release object is returned and the boolean return value will be set to false.

func GetLatest

func GetLatest(releaseType ReleaseType) (*Release, error)

GetLatest is a function that retrieves the latest release of the Golang SDK.

func (Release) FindFiles

func (r Release) FindFiles(os, arch string, kind FileKind) []ReleaseFile

FindFiles is a helper that returns a sub-slice of all files that match the given operating system and architecture. If a file is not specific for an operating system or architecture, it will also be included.

func (Release) GetVersionNumber

func (r Release) GetVersionNumber() *version.Version

GetVersionNumber is a getter that returns the version number for a Golang release. Since the Version field of a release is prefixed by the string "go", this method returns a substring of this fields that is stripped of that exact prefix, to allow easier processing.

type ReleaseFile

type ReleaseFile struct {
	// The filename of the file as it can be found on the download mirror, including the extension.
	Filename string `json:"filename"`
	// The operating system that the file is target at. May be empty if not applicable.
	OS string `json:"os"`
	// The processor architecture that the file is target at. May be empty if not applicable.
	Arch string `json:"arch"`
	// The version of the release the file belongs to.
	Version string `json:"version"`
	// The sha256 checksum that can be used to verify the integrity of the file.
	Sha256 string `json:"sha256"`
	// The size in bytes of the file.
	Size int32 `json:"size"`
	// The kind that this file belongs to.
	Kind FileKind `json:"kind"`
}

ReleaseFile is a that struct holds all information about a file that is part of a released Go version. With each release, a couple of files are distributed, like an installer, a source archive or a binary distribution for different operating systems and architectures. This struct holds information exactly about these files, as part of a Release struct that is obtained by querying the endpoint by the official Golang website.

func (ReleaseFile) GetURL

func (f ReleaseFile) GetURL() string

GetURL is a getter that returns the URL where the receiving file can be downloaded from.

func (ReleaseFile) VerifySame

func (f ReleaseFile) VerifySame(fileName string) (bool, error)

VerifySame is a function that checks if a given file has the correct checksum. It first builds the sha256 of the given file and then compares that value against the Sha256 attribute.

type ReleaseType

type ReleaseType string

The ReleaseType type is a string that describes what kind of release types should be returned by a release list.

func SelectReleaseType

func SelectReleaseType(unstable bool) ReleaseType

SelectReleaseType is a function that returns the release type that matches the input parameters best. For convenience can be used to get the correct release type by describing what kind of releases are desired and the correct release type is then selected by this function. By default IncludeStable is returned.

Jump to

Keyboard shortcuts

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