gosprout

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

README

go-sprout

A utility for automatic watching and updating of a resource

See the examples package for an example until I write a real README

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 Unzip

func Unzip(src, dest string) ([]string, error)

Unzip an archive to multiple files

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.

func ZipFiles

func ZipFiles(src []string, dest string) error

ZipFiles compresses one or many files into a single zip archive file.

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 Serializer added in v0.0.2

type Serializer interface {
	Pointer() interface{}
	sync.Locker
}

type UpdateFunction

type UpdateFunction func(io.Reader)

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 UpdateFromJson added in v0.0.2

func UpdateFromJson(s Serializer) UpdateFunction

Provided a container object which is able to be locked, this function will lock, update the data in the underlying pointer, and unlock. The locking is necessary so this can be done without worry about concurrent access panics.

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.

Jump to

Keyboard shortcuts

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