Documentation ¶
Overview ¶
Package goupdater helps you to easily build self-updating programs
Goupdater makes it easier for you to update your Go programs (or other single-file targets). A program can update itself by replacing its executable file with a new version. It provides the flexibility to implement different updating user experiences like auto-updating, or manual user-initiated updates.
Example (PrivateRepo) ¶
package main import ( "fmt" "github.com/italolelis/goupdater" ) func main() { // we define all the necessary configurations. var ( currentVersion = "v1.2.3" // the version of your app githubToken = "yourToken" // This is only required for private github repositories owner = "hellofresh" repo = "myRepo" ) // We choose the github release resolver. You can implement your own resolver by implementing // the goupdater.Resolver interface resolver, err := goupdater.NewGithub(goupdater.GithubOpts{ Token: githubToken, Owner: owner, Repo: repo, }) if err != nil { panic(err) } // Updates the running binary to the latest available version updated, err := goupdater.Update(resolver, currentVersion) if err != nil { panic(err) } if updated { fmt.Print("You are now using the latest version!") } else { fmt.Print("You already have the latest version!") } }
Output:
Example (PublicRepoWithContext) ¶
package main import ( "context" "fmt" "github.com/italolelis/goupdater" ) func main() { // we define all the necessary configurations. var ( currentVersion = "v1.2.3" // the version of your app owner = "hellofresh" repo = "myRepo" ) // we create a context to be used, this could also be a ContextTimeout that would // fail in case of a network error ctx := context.Background() // We choose the github release resolver. You can implement your own resolver by implementing // the goupdater.Resolver interface resolver, err := goupdater.NewGithubWithContext(ctx, goupdater.GithubOpts{ Owner: owner, Repo: repo, }) if err != nil { panic(err) } // Updates the running binary to the latest available version updated, err := goupdater.UpdateWithContext(ctx, resolver, currentVersion) if err != nil { panic(err) } if updated { fmt.Print("You are now using the latest version!") } else { fmt.Print("You already have the latest version!") } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMissingGithubToken is used when a github token is not provided ErrMissingGithubToken = errors.New("to check for updates you must provide a github token") )
Functions ¶
Types ¶
type Github ¶
type Github struct {
// contains filtered or unexported fields
}
Github represents a github releases resolver
func NewGithubWithContext ¶
NewGithubWithContext creates a new instance of Github and accepts a context param
Click to show internal directories.
Click to hide internal directories.