util

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package util implements general utility functionality for operations such as:

- file operations. - simple http operations. - a set collection implementation. - an unlimited channel (buffered channel) implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src string, dest string) error

CopyFile copies a file from src to dest.

func CopyToStream

func CopyToStream(src string, w io.Writer) (int64, error)

CopyToStream opens the input file specified by src and copies it to the stream specified by w.

func CreatePathForFile

func CreatePathForFile(path string) error

CreatePathForFile creates a directory if one does not exist that can contain the provided file path. no file is created, only the directory path is created.

func DigestFile

func DigestFile(path string) (digest.Digest, error)

DigestFile calculates a SHA256 hash for a given file path. TODO pass an argument to be able to change the digest algorithm.

func DirSize

func DirSize(fsys fs.FS) (int64, error)

DirSize returns the size of a directory.

func GetDirLastUpdate

func GetDirLastUpdate(fsys fs.FS) (time.Time, error)

GetDirLastUpdate returns the last update time of a directory.

func GetDirUpdatedPaths

func GetDirUpdatedPaths(fsys fs.FS, earliest time.Time) ([]string, error)

GetDirUpdatedPaths returns a list of paths that have been updated since the given time.

func IsDirEmpty

func IsDirEmpty(path string) (bool, error)

IsDirEmpty returns true, nil if a directory is empty from https://stackoverflow.com/questions/30697324/how-to-check-if-directory-on-path-is-empty

func UnlimitedChannel

func UnlimitedChannel[T any](cancel context.Context) (in chan T, out chan T)

UnlimitedChannel creates an input/output channel pair that provides the behavior of an unlimited buffered channel. the internal go routine blocks on waiting for items to appear on the input channel, and adds them to a list of items when one is received.

Types

type Set

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

Set provides a set-like container for strings implemented using a map.

func NewSet

func NewSet() *Set

NewSet creates an empty set container.

func NewSetFromList

func NewSetFromList(list []string) *Set

NewSetFromList creates a set from a given slice of strings.

func (*Set) Add

func (s *Set) Add(value string)

Add adds a new string to the set.

func (*Set) Has

func (s *Set) Has(value string) bool

Has returns true if the given value exists in the set.

func (*Set) List

func (s *Set) List() []string

List returns an ordered list of items in the set (sorted).

func (*Set) Remove

func (s *Set) Remove(value string)

Remove deletes a string from the set.

Jump to

Keyboard shortcuts

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