go-latest: github.com/tcnksm/go-latest Index | Files | Directories

package latest

import "github.com/tcnksm/go-latest"

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

Package Files

github.go html.go html_meta.go json.go latest.go

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

type CheckResponse Uses

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.

func Check Uses

func Check(s Source, target string) (*CheckResponse, error)

Check fetches last version information from its source and compares with target and return result (CheckResponse).

type FetchResponse Uses

type FetchResponse struct {
    Versions   []*version.Version
    Malformeds []string
    Meta       *Meta
}

FetchResponse the commom response of Fetch request.

type FixVersionStrFunc Uses

type FixVersionStrFunc func(string) string

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 Uses

func DeleteFrontV() FixVersionStrFunc

DeleteFrontV delete first `v` charactor on version string. For example version name `v0.1.1` becomes `0.1.1`

type GithubTag Uses

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 Uses

func (g *GithubTag) Fetch() (*FetchResponse, error)

func (*GithubTag) Validate Uses

func (g *GithubTag) Validate() error

type HTML Uses

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 Uses

func (h *HTML) Fetch() (*FetchResponse, error)

func (*HTML) Validate Uses

func (h *HTML) Validate() error

type HTMLMeta Uses

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 Uses

func (hm *HTMLMeta) Fetch() (*FetchResponse, error)

func (*HTMLMeta) Validate Uses

func (hm *HTMLMeta) Validate() error

type HTMLScrap Uses

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 Uses

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 Uses

func (j *JSON) Fetch() (*FetchResponse, error)

func (*JSON) Validate Uses

func (j *JSON) Validate() error

type JSONResponse Uses

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 Meta Uses

type Meta struct {
    Message string
    URL     string
}

Meta is meta information from Fetch request.

type Source Uses

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 Uses

type TagFilterFunc func(string) bool

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.

Directories

PathSynopsis
latest

Package latest imports 17 packages (graph) and is imported by 11 packages. Updated 2017-03-15. Refresh now. Tools for package owners.