1
0
mirror of https://github.com/taigrr/go-selfupdate synced 2026-03-20 13:42:38 -07:00

Finished example

This commit is contained in:
Daniel Einspanjer
2016-10-20 00:59:01 -04:00
parent e7050deb55
commit b5f1d9ef43
5 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package main
import (
"log"
"net/http"
)
type logHandler struct {
handler http.Handler
}
func (lh *logHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
log.Printf("\n\texample-server received request %s\n", r.URL.RequestURI())
lh.handler.ServeHTTP(rw,r)
}
func main() {
// Simple static webserver with logging:
log.Fatal(http.ListenAndServe(":8080", &logHandler{handler:http.FileServer(http.Dir("./public"))}))
}

View File

@@ -0,0 +1,24 @@
package main
import (
"log"
"github.com/sanbornm/go-selfupdate/selfupdate"
)
var version string
var updater = &selfupdate.Updater{
CurrentVersion: version, // Manually update the const, or set it using `go build -ldflags="-X main.VERSION=<newver>" -o hello-updater src/hello-updater/main.go`
ApiURL: "http://localhost:8080/", // The server hosting `$CmdName/$GOOS-$ARCH.json` which contains the checksum for the binary
BinURL: "http://localhost:8080/", // The server hosting the zip file containing the binary application which is a fallback for the patch method
DiffURL: "http://localhost:8080/", // The server hosting the binary patch diff for incremental updates
Dir: "update/", // The directory created by the app when run which stores the cktime file
CmdName: "hello-updater", // The app name which is appended to the ApiURL to look for an update
ForceCheck: true, // For this example, always check for an update unless the version is "dev"
}
func main() {
log.Printf("Hello world I am currently version %v", updater.CurrentVersion)
updater.BackgroundRun()
log.Printf("Next run, I should be %v", updater.Info.Version)
}