Documentation ¶
Overview ¶
gosprout is a library which is intended to watch resources and do some processing if the resource gets updated. A resource is defined in a subpackage. It is any source of data - a local file, a net resource, a GCS bucket, a database, etc...
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetErrorHandler ¶
func SetErrorHandler(errorHandler ErrorHandler)
Override the default error behavior. Be default, this will use the standard log.Printf.
func Watch ¶
func Watch(ctx context.Context, interval time.Duration, res resource.Resource, updateFunc UpdateFunction, errorHandler ErrorHandler) <-chan error
Watch sets up a timer which will poll the resource on the provided interval and call the updateFunc if there is a new version available. The errorHandler will be called if there is any issue during processing. The provided ctx defines whether to continue or not - if it is Done() then updates will be permanently stopped.
To use this, the user will need to provide its own logic of what to do with the data of a resource if it is a new version. There are some basic examples defined, but specific business logic will need to be provided in most cases.
Types ¶
type ErrorHandler ¶
type ErrorHandler func(error)
ErrorHandler is a function which takes an error. This will be called during processing if it encounters any issues.
var ( // This will be called on any internal error. In some cases, // an external error handler is provided to a function. If this is the case, the provided // error handler will supercede the default one. If the provided one is nil, the default // will be used. DefaultErrorHandler ErrorHandler = func(e error) { log.Printf("[gosprout] %v\n", e) } )
type UpdateFunction ¶
UpdateFunction is an alias for a function which takes a reader. This is how a user of the library defines the functionality when the file has changed.
func WriteUpdate ¶
func WriteUpdate(w io.Writer) UpdateFunction
WriteUpdate is a simple UpdateFunction. This will take in a provided writer which will be written to with the data from the resource specified. Closing will be handleded by the caller.
Directories ¶
Path | Synopsis |
---|---|
The resource package defines the api for a resource.
|
The resource package defines the api for a resource. |
gcs
The gcs package implements a resource for Google Storage.
|
The gcs package implements a resource for Google Storage. |
net
The net resource is not implemented yet.
|
The net resource is not implemented yet. |