Documentation ¶
Overview ¶
Package cache provides a cache mechanism for the app.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Get = func() (*Cache, error) { p := resolvePath() if _, err := os.Stat(p); os.IsNotExist(err) { if err := initCacheFile(p); err != nil { return nil, errors.Wrap(err, "failed to create a new cache file") } } else if err != nil { return nil, errors.Wrapf(err, "failed to check the existence of cache file '%s'", p) } f, err := os.Open(p) if err != nil { return nil, errors.Wrap(err, "failed to open the cache file") } defer f.Close() var c Cache if err := decodeTOML(f, &c); err != nil { return nil, errors.Wrap(err, "failed to decode loaded cache content") } if c.Version == "" || c.Version != meta.Version.String() { if err := initCacheFile(p); err != nil { return nil, errors.Wrap(err, "failed to clear the cache file") } if _, err := f.Seek(0, 0); err != nil { return nil, errors.Wrap(err, "failed to move to the first") } if err := decodeTOML(f, &c); err != nil { return nil, errors.Wrap(err, "failed to decode cache content") } } return &c, nil }
Get returns loaded cache contents.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { Version string `toml:"version"` UpdateInfo UpdateInfo `toml:"updateInfo"` CommandHistory []string `default:"" toml:"commandHistory"` // SaveFunc is for testing. It will be ignored if it is nil. SaveFunc func() error `toml:"-"` }
Cache represents cached items.
type UpdateInfo ¶ added in v0.7.3
type UpdateInfo struct { LatestVersion string `default:"" toml:"latestVersion"` InstalledBy MeansType `default:"" toml:"installedBy"` }
func (UpdateInfo) UpdateAvailable ¶ added in v0.7.3
func (i UpdateInfo) UpdateAvailable() bool
Click to show internal directories.
Click to hide internal directories.