mirror of
https://github.com/taigrr/go-selfupdate
synced 2026-03-20 13:42:38 -07:00
Finished example
This commit is contained in:
20
example/src/example-server/main.go
Normal file
20
example/src/example-server/main.go
Normal 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"))}))
|
||||
}
|
||||
24
example/src/hello-updater/main.go
Normal file
24
example/src/hello-updater/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user