cache

package
v0.3.47 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cache implements accessing of the state.yml file.

Index

Constants

View Source
const FileName = "state.yml"

FileName denotes the name of the cache file.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, c Cache) context.Context

NewContext derives a context that carries c from ctx.

Types

type Cache

type Cache interface {
	// Dirty reports whether the cache has been mutated since being loaded
	// or initialized.
	Dirty() bool

	// Channel reports the release channel the cache is subscribed to.
	Channel() string

	// SetChannel sets the channel to the one corresponding to the given
	// string. It reports the value the channel was actually set to.
	//
	// Calling SetChannel on a Cache set to a different channel, zeroes out
	// the Cache's release & timestamp information.
	SetChannel(string) string

	// LastCheckedAt reports the last time SetLatestRelease with a non-nil
	// value was called on the Cache.
	LastCheckedAt() time.Time

	// LatestRelease reports the latest release the cache is aware of.
	LatestRelease() *update.Release

	// SetLatestRelease sets the latest release for the given channel.
	//
	// Calling SetLatestRelease for a different channel than the one the Cache
	// is set to has no effect.
	SetLatestRelease(channel string, r *update.Release)

	// SetCurrentVersionInvalid sets the current version of flyctl as invalid
	// because of the given error.
	SetCurrentVersionInvalid(err error)

	// IsCurrentVersionInvalid returns an error message if the given version
	// of flyctl is currently invalid. If not, it returns an empty string.
	IsCurrentVersionInvalid() string

	// Save writes the YAML-encoded representation of c to the named file path via
	// os.WriteFile.
	Save(path string) error
}

Cache wraps the functionality of the local cache file.

func FromContext

func FromContext(ctx context.Context) Cache

FromContext returns the Cache ctx carries. It panics in case ctx carries no Cache.

func Load

func Load(path string) (c Cache, err error)

Load loads the YAML-encoded cache file at the given path.

func New

func New() Cache

New initializes and returns a reference to a new cache.

Jump to

Keyboard shortcuts

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