util

package
v0.0.0-...-62b9041 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package util contains utility types and functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDir

func CheckDir(p string) error

CheckDir checks whether a directory exists and is in fact a directory (returns an error if that is not the case)

func CheckFile

func CheckFile(p string) error

CheckFile checks whether a file exists and is in fact a file (returns an error if that is not the case)

func FilterSongs

func FilterSongs(files []string) []string

FilterSongs removes all non-songs from the files slice

func IsCanceled

func IsCanceled(ctx context.Context) bool

IsCanceled returned whether the context is canceled

func IsDir

func IsDir(p string) bool

IsDir returns true if the path points to an existing directory

func IsFile

func IsFile(p string) bool

IsFile returns true if the path points to an existing file

func ListAllFiles

func ListAllFiles(songsDir string, subDir string) []string

ListAllFiles recursively lists all files in songsDir/subDir

func ListAllSubDirs

func ListAllSubDirs(dir string) []string

ListAllSubDirs recursively lists all directories in dir

func ListGlobFiles

func ListGlobFiles(dir, pattern string) ([]string, error)

ListGlobFiles lists all files in a directory matching the provided glob pattern

Types

type ErrorCollector

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

ErrorCollector is a thread save utility class to collect multiple errors into one slice

func (*ErrorCollector) Add

func (ec *ErrorCollector) Add(err error)

Add adds an error to the ErrorCollector

func (*ErrorCollector) Err

func (ec *ErrorCollector) Err(baseMessage string) error

Err returns an MultiError containing all errors added using Add, with baseMessage as base message If no errors were added, it returns nil

func (*ErrorCollector) Wait

func (ec *ErrorCollector) Wait()

Wait waits for all pending error insertions to complete

type MultiError

type MultiError struct {
	BaseMessage string
	Errors      []error
}

MultiError is an error containing multiple errors

func NewMultiError

func NewMultiError(baseMessage string, errors []error) MultiError

NewMultiError creates a MultiError from a base message and a slice of errors

func (MultiError) Error

func (m MultiError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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