utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst string, dirPerm, filePerm uint32) error

CopyDir copies the content of src to dst. src should be a full path.

func CopyEmbeddedDir

func CopyEmbeddedDir(src fs.FS, dest string, dirPerm, filePerm uint32) error

CopyEmbeddedDir copies directory from the embedded FS into specified directory

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file.

func CopyFileEx

func CopyFileEx(p *CopyFileT) (err error)
func CreateOrReplaceSymlink(symlinkPath, target string) error

See https://stackoverflow.com/a/58148921/3824328

func DirExists

func DirExists(path string) bool

func FileExists

func FileExists(path string) bool

func GetFileList

func GetFileList(path string) ([]string, error)

GetFileList returns a list of regular files in the specified directory. Sub-directories and symlinks are not included.

func GetSortedFileList

func GetSortedFileList(path string, suffix string) ([]string, error)
func GetSymlinkList(path string) ([]string, error)

GetSymlinkList returns a list of symlinks in the specified directory. Sub-directories are not included.

func GetUserConfirmationViaConsole

func GetUserConfirmationViaConsole(prompt string) bool

func ReadTextFile

func ReadTextFile(path string) ([]string, error)

func ReadTextFileEx

func ReadTextFileEx(path string) ([]string, string, error)

ReadTextFileEx reads a text file into lines. Trailing (only) whitespace of each line is trimmed. Returns Lines, LineEnding, error.

func StructToMap

func StructToMap(in any) (map[string]any, error)

StructToMap converts any struct into map[string]any by marshalling it to json and reverse.

func TrimRightSpace

func TrimRightSpace(s string) string

TrimRightSpace trims all trailing whitespace characters. See https://www.danielmorell.com/blog/how-to-trim-whitespace-from-a-string-in-go

Types

type CopyFileT

type CopyFileT struct {
	Src      string
	Dest     string
	FileMode uint32
	// Overwrite         bool
	Overwrite OverwriteActionT

	// PrependPrefix is a prefix to be prepended to
	// each line of the file being copied.
	// Useful to comment out the entire file contents.
	PrependPrefix string
}

type OverwriteActionT

type OverwriteActionT uint32
const (
	OverwriteFatal OverwriteActionT = iota
	OverwriteError
	OverwriteWarn
	OverwriteInfo
	OverwriteSilently
)

Jump to

Keyboard shortcuts

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