selfupdater

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 15 Imported by: 4

README

SelfUpdater

Motivation

Eliminate copy-paste self-update logic across personal CLI projects. Designed for GoReleaser-based release workflows.

Features

  • Automatic version checking against GitHub releases
  • Platform-specific asset selection
  • Checksum verification
  • Safe binary update with rollback support

Installation

go get github.com/marianozunino/selfupdater

Usage

package main

import selfupdater "github.com/marianozunino/selfupdater/pkg/selfupdater"

func main() {
    // Create an updater instance
    updater := selfupdater.NewUpdater(
        "your-github-username",   // GitHub owner
        "your-repo-name",         // Repository name
        "your-binary-name",       // Binary name (matching GoReleaser config)
        "current-version"         // Current version of your application
    )

    // Perform update check and apply if needed
    updater.Update()
}
Optional Authentication

If you're using a private repository or need higher API rate limits:

updater := selfupdater.NewUpdater(
    "owner",
    "repo",
    "binary",
    "version",
    selfupdater.WithToken("your-github-token")
)

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID       int64
	Name     string
	Checksum string
}

type Option

type Option func(*Updater)

func WithToken

func WithToken(token string) Option

type Updater

type Updater struct {
	CurrentVersion string
	Owner          string
	Repo           string
	BinaryName     string
	// contains filtered or unexported fields
}

func NewUpdater

func NewUpdater(owner, repo, binaryName, currentVersion string, options ...Option) *Updater

func (*Updater) Update

func (u *Updater) Update()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL