Documentation ¶
Overview ¶
go-latest is pacakge to check a provided version is latest from various sources.
http://github.com/tcnksm/go-latest
package main import ( "github.com/tcnksm/go-latest" ) githubTag := &latest.GithubTag{ Owner: "tcnksm", Repository: "ghr" } res, _ := latest.Check("0.1.0",githubTag) if res.Outdated { fmt.Printf("version 0.1.0 is out of date, you can upgrade to %s", res.Current) }
Index ¶
Constants ¶
const EnvGoLatestDisable = "GOLATEST_DISABLE"
EnvGoLatestDisable is environmental variable to disable go-latest execution.
const MetaTagName = "go-latest"
MetaTagName is common HTML meta tag name which is defined on https://github.com/tcnksm/go-latest/blob/master/doc/html_meta.md
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckResponse ¶
type CheckResponse struct { // Current is current latest version on source. Current string // Outdate is true when target version is less than Curernt on source. Outdated bool // Latest is true when target version is equal to Current on source. Latest bool // New is true when target version is greater than Current on source. New bool // Malformed store versions or tags which can not be parsed as // Semantic versioning (not compared with target). Malformeds []string // Meta is meta information from source. Meta *Meta }
CheckResponse is a response for a Check request.
type FetchResponse ¶
FetchResponse the commom response of Fetch request.
type FixVersionStrFunc ¶
FixVersionStrFunc is function to fix version string so that it can be interpreted as Semantic Versiongin by http://godoc.org/github.com/hashicorp/go-version
func DeleteFrontV ¶
func DeleteFrontV() FixVersionStrFunc
DeleteFrontV delete first `v` charactor on version string. For example version name `v0.1.1` becomes `0.1.1`
type GithubTag ¶
type GithubTag struct { // Owner and Repository are GitHub owner name and its repository name. // e.g., If you want to check https://github.com/tcnksm/ghr version // Repository is `ghr`, and Owner is `tcnksm`. Owner string Repository string // FixVersionStrFunc is function to fix version string (in this case tag // name string) on GitHub so that it can be interpreted as Semantic Versioning // by hashicorp/go-version. By default, it does nothing. FixVersionStrFunc FixVersionStrFunc // TagFilterFunc is function to filter tags from GitHub. Some project includes // tags you don't want to use for version comparing. It can be used to exclude // such tags. By default, it does nothing. TagFilterFunc TagFilterFunc // URL & Token is used for GitHub Enterprise URL string Token string }
GithubTag is used to fetch version(tag) information from Github.
func (*GithubTag) Fetch ¶
func (g *GithubTag) Fetch() (*FetchResponse, error)
type HTML ¶
type HTML struct { // URL is HTML page URL which include version information. URL string // Scrap is used to scrap a single HTML page and extract version information. // See more about HTMLScrap interface. // By default, it does nothing, just return HTML contents. Scrap HTMLScrap }
HTML is used to fetch version information from a single HTML page.
func (*HTML) Fetch ¶
func (h *HTML) Fetch() (*FetchResponse, error)
type HTMLMeta ¶
type HTMLMeta struct { // URL is HTML page URL which include version information. URL string // Name is tool name which you want to check. This name must be // written in HTML meta tag content field. HTMLMeta use this to // extract version information. Name string }
HTMLMeta is used to fetch a single HTML page and extract version information from specific meta tag. See meta tag specification that HTMLMeta tries to extract on https://github.com/tcnksm/go-latest/blob/master/doc/html_meta.md
func (*HTMLMeta) Fetch ¶
func (hm *HTMLMeta) Fetch() (*FetchResponse, error)
type HTMLScrap ¶
type HTMLScrap interface { // Exec is called from Fetch after fetching a HTMl page from source. // It must return version information as string list format. Exec(r io.Reader) ([]string, *Meta, error) }
HTMLScrap is used to scrap a single HTML page and extract version information.
type JSON ¶
type JSON struct { // URL is URL which return json response with version information. URL string // Response is used to decode json as Struct and extract version information. // See JSONResponse interface. By Default, it is used defaultJSONResponse. Response JSONResponse }
JSON is used to get version information as json format from remote host.
func (*JSON) Fetch ¶
func (j *JSON) Fetch() (*FetchResponse, error)
type JSONResponse ¶
type JSONResponse interface { // VersionInfo is called from Fetch to extract version info. // It must return Semantic Version format version string list. VersionInfo() ([]string, error) // MetaInfo is called from Fetch to extract meta info. MetaInfo() (*Meta, error) }
JSONResponse is used to decode json as Struct and extract information.
type Source ¶
type Source interface { // Validate is called before Fetch in Check. // Source may need to have various information like URL or product name, // so it is used for check each variables are correctly set. // If it is failed, Fetch() will not executed. Validate() error // Fetch is called in Check to fetch information from remote sources. // After fetching, it will convert it into common expression (FetchResponse) Fetch() (*FetchResponse, error) }
Source is the interface that every version information source must implement.
type TagFilterFunc ¶
TagFilterFunc is fucntion to filter unexpected tags from GitHub. Check a given tag as string (before FixVersionStr) and return bool. If it's expected, return true. If not return false.