From f94569ef587225a3cd3e29972de0fbad95f526d0 Mon Sep 17 00:00:00 2001 From: Mark Sanborn Date: Sun, 9 Jul 2023 11:49:23 -0700 Subject: [PATCH] Adds docs and cleanup --- .gitignore | 1 + README.md | 19 +++++++++++-------- example/src/example-server/main.go | 9 ++++++++- example/src/hello-updater/main.go | 4 +++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 9ff57a2..6179d7c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ example/hello-updater example/public/* example/deployment/* example/go-selfupdate +*cktime diff --git a/README.md b/README.md index a7ec0d1..af61d01 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -go-selfupdate -============= +# go-selfupdate [![GoDoc](https://godoc.org/github.com/sanbornm/go-selfupdate/selfupdate?status.svg)](https://godoc.org/github.com/sanbornm/go-selfupdate/selfupdate) [![Build Status](https://travis-ci.org/sanbornm/go-selfupdate.svg?branch=master)](https://travis-ci.org/sanbornm/go-selfupdate) @@ -21,17 +20,21 @@ Enable your Golang applications to self update. Inspired by Chrome based on Her ### Enable your App to Self Update var updater = &selfupdate.Updater{ - CurrentVersion: version, - ApiURL: "http://updates.yourdomain.com/", - BinURL: "http://updates.yourdomain.com/", - DiffURL: "http://updates.yourdomain.com/", - Dir: "update/", - CmdName: "myapp", // app name + CurrentVersion: version, // the current version of your app used to determine if an update is necessary + // these endpoints can be the same if everything is hosted in the same place + ApiURL: "http://updates.yourdomain.com/", // endpoint to get update manifest + BinURL: "http://updates.yourdomain.com/", // endpoint to get full binaries + DiffURL: "http://updates.yourdomain.com/", // endpoint to get binary diff/patches + Dir: "update/", // directory to store temporary state files related to go-selfupdate + CmdName: "myapp", // your app's name (must correspond to app name hosting the updates) + // app name allows you to serve updates for multiple apps on the same server/endpoint } + // go look for an update when your app starts up if updater != nil { go updater.BackgroundRun() } + // your app continues to run... ### Push Out and Update diff --git a/example/src/example-server/main.go b/example/src/example-server/main.go index bb7978c..30a3820 100644 --- a/example/src/example-server/main.go +++ b/example/src/example-server/main.go @@ -1,10 +1,13 @@ package main import ( + "flag" "log" "net/http" ) +var servePath = flag.String("dir", "./public", "path to serve") + type logHandler struct { handler http.Handler } @@ -15,8 +18,12 @@ func (lh *logHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { } func main() { + log.SetFlags(log.LstdFlags | log.Lshortfile) + flag.Parse() + // Simple static webserver with logging: + log.Printf("Starting HTTP server on :8080 serving path %q Ctrl + C to close and quit", *servePath) log.Fatal(http.ListenAndServe(":8080", &logHandler{ - handler: http.FileServer(http.Dir("./public"))}, + handler: http.FileServer(http.Dir(*servePath))}, )) } diff --git a/example/src/hello-updater/main.go b/example/src/hello-updater/main.go index 99a0a66..90446fe 100644 --- a/example/src/hello-updater/main.go +++ b/example/src/hello-updater/main.go @@ -25,13 +25,15 @@ var updater = &selfupdate.Updater{ } func main() { + log.SetFlags(log.LstdFlags | log.Lshortfile) + // print the current version log.Printf("(hello-updater) Hello world! I am currently version: %q", updater.CurrentVersion) // try to update err := updater.BackgroundRun() if err != nil { - log.Fatal(err) + log.Fatalln("Failed to update app:", err) } // print out latest version available