fs

package module
v3.0.0-...-ff147df Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src, dst string) (int64, error)

Copy lets you copy files from the src to the dst

func GetFileFromParent

func GetFileFromParent(root string, start string, search string) (string, bool)

GetFileFromParent checks if the parent (or sub parent) directory of a file contains a specific file or folder

@root is the highest grandparent to check before quitting

@start is the lowest level to start searching from (if a directory is passed, it will not be included in your search)

@search is what file you want to search from

func JoinPath

func JoinPath(path ...string) (string, error)

JoinPath joins multiple file types with safety from backtracking

func ReadConfig

func ReadConfig(path string, out interface{}) error

ReadConfig loads a config file into a struct

this method will read the buffer, and normalize names so '-' and '_' characters are optional, and everything is lowercase

this method will try different file types in the following order:

[yml, yaml, json]

you can specify the first file type to try, by adding a .ext of that file type to the path

by accepting moltiple file types, the user can choose what type of file they want to use for their config file

func ReadJson

func ReadJson(path string, out interface{}) error

ReadJson loads a json file into a struct

this method will read the buffer, and normalize names so '-' and '_' characters are optional, and everything is lowercase

this method is useful for loading a config file

func ReadYaml

func ReadYaml(path string, out interface{}) error

ReadYaml loads a yaml file into a struct

this method will read the buffer, and normalize names so '-' and '_' characters are optional, and everything is lowercase

this method is useful for loading a config file

func ReplaceRegex

func ReplaceRegex(name string, re string, rep []byte, all bool, maxReSize ...int64) error

ReplaceRegex replaces a regex match with a new []byte in a file

@all: if true, will replace all text matching @re, if false, will only replace the first occurrence

func ReplaceRegexFunc

func ReplaceRegexFunc(name string, re string, rep func(data func(int) []byte) []byte, all bool, maxReSize ...int64) error

ReplaceRegexFunc replaces a regex match with the result of a callback function in a file

@all: if true, will replace all text matching @re, if false, will only replace the first occurrence

func ReplaceText

func ReplaceText(name string, search []byte, rep []byte, all bool) error

ReplaceText replaces a []byte with a new one in a file

@all: if true, will replace all text matching @search, if false, will only replace the first occurrence

Types

type FileWatcher

type FileWatcher struct {

	// when a file changes
	//
	// @path: the file path the change happened to
	//
	// @op: the change operation
	OnFileChange func(path string, op string)

	// when a directory is added
	//
	// @path: the file path the change happened to
	//
	// @op: the change operation
	//
	// return false to prevent that directory from being watched
	OnDirAdd func(path string, op string) (addWatcher bool)

	// when a file or directory is removed
	//
	// @path: the file path the change happened to
	//
	// @op: the change operation
	//
	// return false to prevent that directory from no longer being watched
	OnRemove func(path string, op string) (removeWatcher bool)

	// every time something happens
	//
	// @path: the file path the change happened to
	//
	// @op: the change operation
	OnAny func(path string, op string)
	// contains filtered or unexported fields
}

A watcher instance for the `FS.FileWatcher` method

func Watcher

func Watcher() *FileWatcher

func (*FileWatcher) CloseWatcher

func (fw *FileWatcher) CloseWatcher(root string) error

CloseWatcher will close the watcher by the root name you used

@root pass a file path for a specific watcher or "*" for all watchers that exist

func (*FileWatcher) Wait

func (fw *FileWatcher) Wait()

Wait for all Watchers to close

func (*FileWatcher) WatchDir

func (fw *FileWatcher) WatchDir(root string, nosub ...bool) error

WatchDir watches the files in a directory and its subdirectories for changes

@nosub: do not watch sub directories

Jump to

Keyboard shortcuts

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