Skip to content

Commit

Permalink
Adds docs and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbornm committed Jul 9, 2023
1 parent 69abd32 commit f94569e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ example/hello-updater
example/public/*
example/deployment/*
example/go-selfupdate
*cktime
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
9 changes: 8 additions & 1 deletion example/src/example-server/main.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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))},
))
}
4 changes: 3 additions & 1 deletion example/src/hello-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f94569e

Please sign in to comment.