• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple way to check version is latest or not from various sources in Golang

go-latest

GitHub release Wercker MIT License Go Documentation

go-latest is a package to check a provided version is latest or not from various sources.

Once you distribute your tool by golang and user start to use it, it's difficult to tell users that new version is released and encourage them to use new one. go-latest enables you to do that by just preparing simple source. For sources, currently you can use tags on Github, HTML meta tag (HTML scraping) and JSON response.

See more details in document at https://godoc.org/github.com/tcnksm/go-latest.

Install

To install, use go get:

$ go get -d github.com/tcnksm/go-latest

Usage

For sources to check, currently you can use tags on Github, HTML meta tag (HTML scraping) and JSON response.

Github Tag

To check 0.1.0 is the latest in tags on GitHub.

githubTag := &latest.GithubTag{
    Owner: "username",
    Repository: "reponame",
}

res, _ := latest.Check(githubTag, "0.1.0")
if res.Outdated {
    fmt.Printf("0.1.0 is not latest, you should upgrade to %s", res.Current)
}

go-latest uses Semantic Versioning to compare versions. If tagging name strategy on GitHub is different from it, you need to fix it with FixVersionStrFunc. For example, if you add v charactor in the begining of version string like v0.1.0, you need to transform it to 0.1.0, you can use DeleteFrontV() function like below,

githubTag := &latest.GithubTag{
    Owner:             "username",
    Repository:        "reponame",
    FixVersionStrFunc: latest.DeleteFrontV(),
}

You can define your own FixVersionStrFunc. See more on https://godoc.org/github.com/tcnksm/go-latest

HTML meta tag

You can use simple HTTP+HTML meta tag for a checking source.

For example, if you have a tool named reduce-worker and want to check 0.1.0 is latest or not, prepare HTML page which includes following meta tag,

<meta name="go-latest" content="reduce-worker 0.1.1 New version include security update">

And make request,

html := &latest.HTMLMeta{
    URL: "http://example.com/info",
    Name: "reduce-worker",
}

res, _ := latest.Check(html, "0.1.0")
if res.Outdated {
    fmt.Printf("0.1.0 is not latest, %s, upgrade to %s", res.Meta.Message, res.Current)
}

To know about HTML meta tag specification, see HTML Meta tag.

You can prepare your own HTML page and its scraping function. See more details in document at https://godoc.org/github.com/tcnksm/go-latest.

JSON

You can also use a JSON response.

If you want to check 0.1.0 is latest or not, prepare an API server which returns a following response,

{
    "version":"1.2.3",
    "message":"New version include security update, you should update soon",
    "url":"http://example.com/info"
}

And make request,

json := &latest.JSON{
    URL: "http://example.com/json",
}

res, _ := latest.Check(json, "0.1.0")
if res.Outdated {
    fmt.Printf("0.1.0 is not latest, %s, upgrade to %s", res.Meta.Message, res.Current)
}

You can use your own json schema by defining JSONReceive interface. See more details in document at https://godoc.org/github.com/tcnksm/go-latest.

Version comparing

To compare version, we use hashicorp/go-version. go-version follows Semantic Versioning. So to use go-latest you need to follow SemVer format.

For user who doesn't use SemVer format, go-latest has function to transform it into SemVer format.

Contribution

  1. Fork (https://github.com/tcnksm/go-latest/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

Author

Taichi Nakashima

More Repositories

1

ghr

Upload multiple artifacts to GitHub Release in parallel
Go
1,234
star
2

gcli

The easy way to build Golang command-line application.
Go
921
star
3

go-httpstat

Tracing golang HTTP request latency
Go
421
star
4

docker-alias

My Docker alias and functions
Shell
372
star
5

go-slack-interactive

Sample slack bot which uses slack interactive message (button & menue) written in Golang
Go
306
star
6

gotests

[Archived] A tool to generate Go test functions from the given source code like gofmt
Go
264
star
7

go-input

Go package for ideal tty prompt
Go
253
star
8

awesome-container

A curated list of awesome container technologies and services
174
star
9

license

Generate LICENSE file you want
Go
117
star
10

go-casper

Cache aware server push (CASPer) in Golang
Go
108
star
11

go-binary-only-package

Sample of Go1.7 Binary-Only Packages
Go
79
star
12

dockerfile-rbenv

Dockerfile to build Image which is installed muliple versions of ruby
76
star
13

go-gitconfig

Use gitconfig values in Golang.
Go
59
star
14

boot2kubernetes

Run single node kubernetes cluseter in one command
Go
37
star
15

dockerfile-gox

Docekerfile for gox, cross-compiling golang project parallelly
Dockerfile
36
star
16

dotfiles

@tcnksm does dotfiles
Shell
30
star
17

waypoint-plugin-kustomize

Experimental implementation of waypoint plugin for kustomize
Go
30
star
18

talks

@tcnksm talks at conference or on Podcast
Go
27
star
19

rbdock

Generate Dockerfile for Ruby or Rails, Sinatra.
Ruby
24
star
20

deeeet.com

@tcnksm writes blog
SCSS
24
star
21

dutyme

Assign PagerDuty on-call to you while operation
Go
23
star
22

go-algorithms

Algorithms and data structure by golang
Go
21
star
23

go-distributed-tracing

Sample kubernetes config and golang apps to try distributed tracing with Stackdriver
Go
20
star
24

vagrant-digitalocean-coreos

Create CoreOS cluster on DigitalOcean by Vagrant
19
star
25

go-crypto

Play with golang crypto package
Go
19
star
26

go-holidayjp

Go package for detecting holiday in Japan
Go
15
star
27

gox-server

Golang cross-compile on Heroku
Go
15
star
28

docker-link-pattern

Docker container link patterns
Ruby
13
star
29

alexa-irkit-ac

A sample implementation of custom Alexa Smart Home Skill by Golang
Go
12
star
30

sudo-controller

Kubernetes controller which allows you to create time bound role binding with approval.
Go
11
star
31

go-reconcile

Super tiny go package which does reconcile planning
Go
11
star
32

vagrant-secret

Enable to read external secret file for configuration
Ruby
10
star
33

wercker-step-ghr

Wercker step for tcnksm/ghr, create Github Release and uploading artifacts
Shell
10
star
34

go-irkit

The unofficial golang client for IRKit
Go
9
star
35

vagrant-pushover

Add pushover notification to your vagrant
Ruby
9
star
36

docc

docc open your project document (GitHub page or README)
Go
9
star
37

dockerfile-centos-buildpack-deps

Docker CentOS Image for buildpack-deps
9
star
38

yo

Yo to your twitter friend from CLI
Go
8
star
39

misc

The collection of programs which is not general consumption
Go
8
star
40

heroku-docker-registry

Run Docker Registry on Heroku
Shell
8
star
41

rspec-logstash-filter

RSpec logstash filter on docker container
Shell
7
star
42

bash-init

The easy way to start building bash command-line application.
Go
7
star
43

docker-meetup-4-demo

Demo for docker meetup #4
Shell
7
star
44

vagrant-runc

Play with runC on Ubuntu14.04 by Vagrant
7
star
45

dockerfile-single-kafka

Dockerfile for single node kafka
Shell
7
star
46

wercker-box-gox

Wercker box for mitchellh/gox, cross-compiling golang project parallelly
6
star
47

go-httptraceutils

Small Go helper package for logging out each hook info of httptrace
Go
6
star
48

wercker-step-goveralls

Wercker step for mattn/goveralls, integrate with coveralls.io
Shell
5
star
49

go-context101

Sample codes to understand why context package
Go
5
star
50

go-distribution-scripts

Shellscripts for cross-compiling, packaging and uploading golang tool
Shell
5
star
51

hubot-google-trend

Hubot script to show recent trend words on Google
CoffeeScript
5
star
52

wercker-step-zip

Wercker step for packaging directories
Shell
4
star
53

dockerfiles

@tcnksm does Dockerfile
4
star
54

vagrant-appc

Play with CoreOS/Rocket in Vagrant
4
star
55

hubot-cron-json

Manage hubot cron job defined by json configuration file
CoffeeScript
4
star
56

wercker-step-gox

Wercker step for mitchellh/gox, cross-compiling golang project parallelly
Shell
4
star
57

oh-my-zsh-beer-theme

oh-my-zsh ๐Ÿบ theme
3
star
58

tf-dnsimple-gh-pages

Setup custom apex domain for your GitHub pages with Terraform
HCL
3
star
59

coreos-meetup-tokyo

CoreOS meetup tokyo
3
star
60

init

Initial template
Go
2
star
61

random_japanese_string

Generate random japanese strings
Ruby
2
star
62

retrobot

tweet what @tcnksm tweet 1 year ago
Ruby
2
star
63

dockerfile-go-release

Dockerfile for cross-compiling & uploading artifacts to Github Release page. Compiling and uploading are executed parallelly.
Shell
2
star
64

dist-ghr

Redirect distribution for
Go
2
star
65

go-playground

My Go Playground
Go
1
star
66

tcnksm.github.io

HTML
1
star
67

homebrew-ghr

A Homebrew formula for tcnksm/ghr
Ruby
1
star
68

tcnksm

README for @tcnksm
Go
1
star
69

ghr-demo

GHR demo
Go
1
star
70

go-cf-manifest

Go package for handling CloudFoundry manifest.yml
Go
1
star
71

dockerfile-download-deb

Dockerfile for donwloading deb package
1
star
72

scripts

Automation scripts for my daily job/life
Shell
1
star
73

writing.deeeet.com

My blog powered by octopress
Ruby
1
star