- 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.
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
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)
}
}
}