utils

package
v0.0.0-...-941ac12 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPath

func CheckPath(path string) error

CheckPath checks if the path exists

func CloseFile

func CloseFile(file *os.File) error

CloseFile closes the file provided

func CreateAllDir

func CreateAllDir(path string) error

CreateAllDir creates all directories up to the path provided

func CreateAllDirIfNotExist

func CreateAllDirIfNotExist(path string) error

CreateAllDirIfNotExist creates all directories if they do not already exist up to the path provided

func CreateBuildDirIfNotExist

func CreateBuildDirIfNotExist(buildDir string) error

CreateBuildDirIfNotExist creates the build directory if it does not already exist

func CreateFile

func CreateFile(path string, content []byte) (*os.File, error)

CreateFile creates a file with the given content at the path provided

func CurrentAbsolutePath

func CurrentAbsolutePath(relPath string) (string, error)

CurrentAbsolutePath is a absolute representation of the relative path provided by taking the current root path into account

func CurrentRootPath

func CurrentRootPath() (string, error)

CurrentRootPath is the current root path

func FileChecksum

func FileChecksum(path string) (string, error)

FileChecksum calculates a new checksum for the given path

func IsCreate

func IsCreate(ev fsnotify.Event) bool

IsCreate checks if the fsnotify event is a create

func IsDir

func IsDir(path string) (bool, error)

IsDir checks if the path is a directory

func IsRemove

func IsRemove(ev fsnotify.Event) bool

IsRemove checks if the fsnotify event is a remove

func IsWrite

func IsWrite(ev fsnotify.Event) bool

IsWrite checks if the fsnotify event is a write

func OpenFile

func OpenFile(path string) (*os.File, error)

OpenFile opens a file at the path provided

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile is the file read at the path provided

func RelPath

func RelPath(root string, path string) (string, error)

RelPath is a relative representation of the absolute path provided

func RemoveAllDir

func RemoveAllDir(path string) error

RemoveAllDir removes all directories up to the path provided

func RemoveFile

func RemoveFile(filePath string) error

RemoveFile removes a file at the path provided

func RemoveFileIfExist

func RemoveFileIfExist(path string) error

RemoveFileIfExist removes a file if it does already exist at the path provided

func RemoveRootBuildDir

func RemoveRootBuildDir(relBuildDir string) error

RemoveRootBuildDir removes the given build dir at it's root

func RemoveRootDir

func RemoveRootDir(relPath string) error

RemoveRootDir removes all directories up to the relative path provided

func WithLock

func WithLock(mu *sync.Mutex, f func())

WithLock runs the given operation in a blocking manner

func WithLockAndError

func WithLockAndError(mu *sync.Mutex, f func() error) error

WithLockAndError runs the given operation in a blocking manner and returns any errors

func WriteFile

func WriteFile(file *os.File, content []byte) error

WriteFile writes to a file the content provided

Types

type Batcher

type Batcher struct {
	*fsnotify.Watcher

	Events chan []fsnotify.Event
	Errors chan []error
	// contains filtered or unexported fields
}

Batcher collects detected file changes throughout a given time interval.

func NewBatcher

func NewBatcher(interval time.Duration) (*Batcher, error)

NewBatcher creates and runs a Batcher with the given time interval.

func (*Batcher) Close

func (b *Batcher) Close()

Close stops the Batcher

type FileChecksums

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

FileChecksums is a thread-safe map that stores file checksums

func NewFileChecksums

func NewFileChecksums() *FileChecksums

NewFileChecksums creates a new file checksums map

func (*FileChecksums) HasChanged

func (c *FileChecksums) HasChanged(path string, checksum string) bool

HasChanged checks if the checksum for the given path has changed in a thread safe manner

func (*FileChecksums) UpdateFileChecksum

func (c *FileChecksums) UpdateFileChecksum(path string, checksum string)

UpdateFileChecksum updates the checksum for the given path in a thread-safe manner

Jump to

Keyboard shortcuts

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