dirloader

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

Package dirloader provides a loader based on the local directory to load some resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirLoader

type DirLoader[T any] struct {
	// contains filtered or unexported fields
}

DirLoader is used to load the resources from the files in a directory.

func New

func New[T any](dir string) *DirLoader[T]

New returns a new DirLoader with the directory.

func (*DirLoader[T]) Load

func (l *DirLoader[T]) Load() (resources []T, etag string, err error)

Load scans the files in the directory, loads and returns them if changed.

func (*DirLoader[T]) Resource

func (l *DirLoader[T]) Resource() *resource.Resource[[]T]

Resource returns the inner resource.

func (*DirLoader[T]) SetDecoder added in v0.2.0

func (l *DirLoader[T]) SetDecoder(decode func(data []byte, dst any) error) *DirLoader[T]

SetDecoder sets the resource decoder.

func (*DirLoader[T]) SetEtagEncoder added in v0.4.0

func (l *DirLoader[T]) SetEtagEncoder(encode func(changed time.Time) string) *DirLoader[T]

SetEtagEncoder sets the etag encoder.

func (*DirLoader[T]) Sync

func (l *DirLoader[T]) Sync(ctx context.Context, rsctype string, interval time.Duration, reload <-chan struct{}, cb func([]T))

Sync is used to synchronize the resources to the chan ch periodically.

If cb is nil, never call it when reload the resources.

Jump to

Keyboard shortcuts

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