Skip to content

golang library for self updating programs

License

Notifications You must be signed in to change notification settings

FabienM/updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

updater: golang library for self updating programs

Features

  • update from repository (HTML index)
  • Semantic Versioning support This repository is a golang library that provides an auto-updater embeddable in your go binary.

Updates are to be fetched from a repository. Currently only basic HTML indexes are supported, such as those generated by Sonatype Nexus.

Installation

You are free to go get the lib as any golang library but the prefered way to install it is using dep.

dep ensure -add github.com/fabienm/updater

Code examples

For the sake of simplicity, errors are silenced in this example.

package main
import (
	"fmt"
	"os"
	"strings"
	
	"github.com/fabienm/updater"
)

var version = "1.0.1"

func main() {
	u:= updater.New(updater.Config{
		BinaryName: "mybinary",
		Repository:"http://example/nexus/content/repositories/releases",
	})
	build, _:= u.FindLatest()

	if build.NewerThan(version) {
		fmt.Printf("Do you want to update to %s? [Y/n]\n", build.Version)
		input:= "y"
		fmt.Scanln(&input)
		if strings.ToLower(input[0:0]) == "y" {
			u.UpdateTo(build)
			os.Exit(0)
		} 
	}
}

About

golang library for self updating programs

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages