update

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package update checks GitHub for a newer openapi-generator and replaces this binary with it. Releases publish one bare binary per platform plus a CHECKSUMS.txt; nothing is installed that the checksum file does not cover.

Index

Constants

View Source
const Dev = "dev"

Dev is the version a build without -ldflags reports. It is never offered an update, so a working copy is not nagged about the release it is ahead of.

View Source
const Repo = "xseman/openapi-generator"

Repo is the GitHub repository releases are published to.

Variables

View Source
var API = "https://api.github.com/repos/" + Repo + "/releases/latest"

API is the latest-release endpoint. The tests point it at a local server.

View Source
var Path = func() (string, error) {
	exe, err := os.Executable()
	if err != nil {
		return "", err
	}

	if p, err := filepath.EvalSymlinks(exe); err == nil {
		return p, nil
	}

	return exe, nil
}

Path is this executable with its symlinks resolved: the file an update replaces. It is a variable so a test can aim an install at a scratch file instead of the binary running it.

View Source
var Version = Dev

Version is the release this binary was built from, set at link time with `-X github.com/xseman/openapi-generator/internal/update.Version=1.2.3`.

Functions

func Asset

func Asset() string

Asset is the name this platform's binary has in a release.

func Compare

func Compare(a, b string) int

Compare orders two dotted versions as -1, 0 or +1. A pre-release suffix ("1.2.3-rc1") is cut off, and a field that is not a number counts as 0, so Dev sorts below every release.

func Download

func Download(ctx context.Context, rel Release, dir string, progress func(done, total int64)) (string, error)

Download fetches the release binary into dir and returns the path of the file, which is left there only when its SHA-256 matches. progress, when it is not nil, is called as bytes arrive; total is 0 when the server sends no length.

func Install

func Install(ctx context.Context, rel Release, progress func(done, total int64)) error

Install downloads rel and puts it where this executable is. The running process keeps the binary it started from — the new one runs at the next start, which is why the caller tells the user to restart.

Types

type Release

type Release struct {
	Version string `json:"version"`
	URL     string `json:"url"`
	SHA256  string `json:"sha256"`
	Notes   string `json:"notes,omitempty"`
}

Release is the newest published openapi-generator: its version, where this platform's binary is, and what that binary must hash to.

func Check

func Check(ctx context.Context) (Release, error)

Check asks GitHub for the latest release and the checksum its CHECKSUMS.txt records for this platform's binary.

func (Release) Newer

func (r Release) Newer() bool

Newer reports whether r is a release above this build. A Dev build is behind every release, so Newer is false for it: only an explicit `openapi-generator update` replaces a build that was not made from a tag.

Jump to

Keyboard shortcuts

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