updater

package
v1.1.20 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package updater provides functionality to check for newer releases of an application hosted on GitHub.

It queries the GitHub Releases API to retrieve the latest release and compares its tag against the current application version using semantic versioning.

Usage

cfg := &updater.Config{
	Owner:      "deep-rent",
	Repository: "vouch",
	Current:    "v1.0.0",
	UserAgent:  "Vouch/1.0.0",
}

// Check for updates.
rel, err := updater.Check(context.Background(), cfg)
if err != nil {
	log.Printf("Failed to check for updates: %v", err)
} else if rel != nil {
	log.Printf("New version available: %s (see %s)", rel.Version, rel.URL)
}

Index

Constants

View Source
const (
	// DefaultBaseURL is the default GitHub API base URL.
	DefaultBaseURL = "https://api.github.com"
	// DefaultTimeout is the default timeout for HTTP requests.
	DefaultTimeout = 5 * time.Second
)

Default configuration values for the updater.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BaseURL is the base URL for the GitHub API. It defaults to DefaultBaseURL
	// if not set. This is primarily used for testing purposes.
	BaseURL string
	// Owner is the GitHub repository owner (required).
	Owner string
	// Repository is the name of the GitHub repository (required).
	Repository string
	// Current is the current version string of the application (required).
	Current string
	// UserAgent is the value for the User-Agent header sent with requests.
	// If empty, no User-Agent header is sent.
	UserAgent string
	// Timeout is the time limit for requests made by the updater.
	// It defaults to 5 seconds if not set.
	Timeout time.Duration
}

Config holds the configuration for the Updater.

type Release

type Release struct {
	// Version is the tag name of the release (e.g., "v1.0.0").
	Version string `json:"tag_name"`
	// URL to view the release on GitHub.
	URL string `json:"html_url"`
	// Published is the timestamp the release was published on GitHub.
	Published time.Time `json:"published_at"`
	// Notes contains the release notes or description.
	Notes string `json:"body"`
}

Release represents a published release on GitHub.

func Check

func Check(ctx context.Context, cfg *Config) (*Release, error)

Check is a convenience function to check for updates in a single call. It creates a temporary Updater with the provided config and calls its Check method.

type Updater

type Updater struct {
	// contains filtered or unexported fields
}

Updater checks for updates on GitHub for a specific repository.

func New

func New(cfg *Config) *Updater

New creates a new Updater with the given configuration.

It initializes the HTTP client with the specified timeout. It panics if the configuration is invalid (missing required fields) or if the current version string is not a valid semantic version (after normalizing it with a "v" prefix if missing).

func (*Updater) Check

func (u *Updater) Check(ctx context.Context) (*Release, error)

Check queries the GitHub Releases API to determine if a newer version is available.

It compares the latest release tag against the current version using semantic versioning. Both versions are normalized with a "v" prefix if missing. It returns a Release if a newer version is found. It returns nil if the current version is up-to-date or if the latest release is older or equal. It returns an error if the GitHub API request fails or if the latest release tag is not a valid semantic version.

Jump to

Keyboard shortcuts

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