reload
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package reload contains functions that allow periodically reloading a value(e.g. a config file) from various sources.
Index¶
Constants¶
const DefaultInterval = 5 *time.MinuteDefaultInterval is the default value for ReloadOpts.Interval if none isprovided.
Variables¶
This section is empty.
Functions¶
funcNew¶
func New[Tany](ctxcontext.Context, optsReloadOpts[T]) (func() T,error)
New creates and starts reloading the provided value as per opts. It returnsa function that, when called, returns the current stored value, or an errorthat indicates something went wrong.
The value will be present immediately upon return.
Types¶
typeReloadOpts¶
type ReloadOpts[Tany] struct {// Read is called to obtain the data to be unmarshaled; e.g. by reading// from a file, or making a network request, etc.//// An error from this function is fatal when calling New, but only a// warning during reload.//// This value is required.Read func(context.Context) ([]byte,error)// Unmarshal is called with the data that the Read function returns and// should return a parsed form of the given value, or an error.//// An error from this function is fatal when calling New, but only a// warning during reload.//// This value is required.Unmarshal func([]byte) (T,error)// Logf is a logger used to print errors that occur on reload. If nil,// no messages are printed.Logflogger.Logf// Interval is the interval at which to reload the given data from the// source; if zero, DefaultInterval will be used.Intervaltime.Duration// IntervalJitter is the jitter to be added to the given Interval; if// provided, a duration between 0 and this value will be added to each// Interval when waiting.IntervalJittertime.Duration}
ReloadOpts specifies options for reloading a value. Various helper functionsin this package can be used to create one of these specialized for a givenuse-case.
funcFromJSONFile¶
func FromJSONFile[Tany](pathstring)ReloadOpts[T]
FromJSONFile creates a ReloadOpts describing reloading a value of type Tfrom the given JSON file on-disk.