cache

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheFile  = "nautical_cache.json"
	TimeLayout = "2006-01-02_15-04-05"
)

Variables

This section is empty.

Functions

func FindCacheDir

func FindCacheDir() (string, error)

FindCacheDir will find the nautical cache directory. First the environment variable NAUTICAL_CACHE_DIR is searched for. If this environment variable is not found, then the operating system is searched and directory is returned according to the system.

func FindCacheFile

func FindCacheFile() (string, error)

FindCacheFile find the full path to the cache file.

func ShouldUpdate

func ShouldUpdate(originalTime time.Time, minMinutesDifference int) bool

ShouldUpdate will determine if the cache should be updated based on the time difference (provided) that is the min difference allowed before an update will occur.

Types

type NauticalCache

type NauticalCache struct {
	// Buoys is the list of all buoys that are to be cached
	Buoys []noaa.Buoy `json:"buoys,omitempty"`

	// Sources is the list of all sources that are to be cached
	Sources []noaa.Source `json:"sources,omitempty"`

	// Time that the cache was created
	Time string `json:"time,omitempty"`
}

NauticalCache contains the Buoys, Sources, and Time data for a cached instance

type NauticalCacheData

type NauticalCacheData struct {
	// Full Filename (including path) to the cached data
	Filename string

	// CachedData is structure holding all cached data
	CachedData *NauticalCache
}

NauticalCacheData is a wrapper for the NauticalCache struct that includes the Filename where the data is stored

func Load

func Load(filename string) (*NauticalCacheData, error)

Load will load the data from a file into the NauticalCacheData

func (*NauticalCacheData) CopyCurrentCache

func (cache *NauticalCacheData) CopyCurrentCache(extra_data string) error

CopyCurrentCache copies the current cached data to a new file where the extra data is appended to the original cached filename

func (*NauticalCacheData) CopyCurrentCacheWithTimestamp

func (cache *NauticalCacheData) CopyCurrentCacheWithTimestamp() error

CopyCurrentCacheWithTimestamp Copies the data of the original file and renames the file with a timestamp.

func (*NauticalCacheData) Dump

func (cache *NauticalCacheData) Dump() error

Dump outputs the nautical cache data to the filename specified in the cache struct

func (*NauticalCacheData) New

func (cache *NauticalCacheData) New() error

func (*NauticalCacheData) ShouldUpdate

func (cache *NauticalCacheData) ShouldUpdate(minMinutesDifference int) bool

ShouldUpdate will determine if an update should occur based on the time stored in the CacheData

Jump to

Keyboard shortcuts

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