util

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TTLEternal is a TTL value for eternal cache.
	TTLEternal = time.Duration(-1)

	MetaSuffix = "--meta"

	DirsMode  os.FileMode = 0755
	FilesMode os.FileMode = 0644
)

Variables

View Source
var (
	ErrDirNotExists = errors.New("directory does not exist")
	ErrNotADir      = errors.New("not a directory")
)

Functions

func CopyWithCtx

func CopyWithCtx(ctx context.Context, dst io.Writer, src io.Reader) (readN int64, err error)

CopyWithCtx is a wrapper for the io.CopyWithCtx function with context handling.

func CreateCacheFile

func CreateCacheFile(key string, path string) (*os.File, error)

func DeleteCacheFiles

func DeleteCacheFiles(paths ...string)

DeleteCacheFiles removes cache files

func FilterPathIdent

func FilterPathIdent(ident string) string

FilterPathIdent remove path separators from the path part.

func FixSeparators

func FixSeparators(path string) string

FixSeparators replaces all path separators with the OS-correct.

func GetItemPath

func GetItemPath(dir string, pathGenerator PathGeneratorFn, key string, forMeta bool, createDirs bool) string

GetItemPath returns full item's path.

func IsExpired

func IsExpired(createdAt time.Time, ttl time.Duration) bool

IsExpired checks if item is expired.

func ItemFilesValid

func ItemFilesValid(itemPath string, metaPath string) bool

ItemFilesValid checks if itemPath & metaPath are a valid files' paths.

func PrepareDir

func PrepareDir(dir string) error

PrepareDir checks if dir exists and creates it otherwise.

func ReadAll

func ReadAll(ctx context.Context, r io.Reader) ([]byte, error)

ReadAll is an alias for an io.ReadAll, but with context cancel respect.

Types

type KeyLocker

type KeyLocker struct {
	sync.Mutex
}

type KeysLocker

type KeysLocker struct {
	// contains filtered or unexported fields
}

func NewKeysLocker

func NewKeysLocker() *KeysLocker

func (*KeysLocker) Lock

func (k *KeysLocker) Lock(key string)

func (*KeysLocker) Unlock

func (k *KeysLocker) Unlock(key string)

type PathGeneratorFn

type PathGeneratorFn func(key string) string

type ReaderFunc

type ReaderFunc func(p []byte) (n int, err error)

func (ReaderFunc) Read

func (rf ReaderFunc) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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