util

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: Unlicense Imports: 13 Imported by: 10

README

go_util

Go Utility Functions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst *Path) error

CopyDir copies from the given directory (src) and all of its files to the destination (dst).

func CopyFile

func CopyFile(src, dst *Path) error

CopyFile copies a file given by its path (src) creating an output file given its path (dst)

func ErrorString

func ErrorString(err error) string

func FileCompareEqual

func FileCompareEqual(file1, file2 *Path) bool

FileCompareEqual compares two files returning true if they are equal.

func FormatArgs

func FormatArgs(args ...interface{}) string

func PanicIf

func PanicIf(cond bool, args ...interface{})

func PanicIfErr

func PanicIfErr(err error, args ...interface{})

func ReadJsonFile

func ReadJsonFile(jsonPath string) (interface{}, error)

ReadJsonFile preprocesses out comments and then unmarshals the data generically.

func ReadJsonFileToData

func ReadJsonFileToData(jsonPath string, jsonOut interface{}) error

ReadJsonFileToData preprocesses out comments and then unmarshals the data into a data structure previously defined.

Types

type ExecCmd

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

os.Exec contains further details

func NewExecCmd

func NewExecCmd(name string, args ...string) *ExecCmd

func (*ExecCmd) Cmd

func (c *ExecCmd) Cmd() *exec.Cmd

func (*ExecCmd) CommandString

func (c *ExecCmd) CommandString() string

func (*ExecCmd) QuoteArgIfNeeded

func (c *ExecCmd) QuoteArgIfNeeded(n int) string

func (*ExecCmd) Run

func (c *ExecCmd) Run() error

Runt runs the previously set up command.

func (*ExecCmd) RunWithOutput

func (c *ExecCmd) RunWithOutput() (string, error)

RunWithOutput runs the previously set up command, gets the combined output of sysout and syserr, trims whitespace from it and returns if error free. If any error occurs, it is simply returned.

type Path

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

Path provides a centralized

func NewHomeDir

func NewHomeDir() *Path

NewHomeDir returns the current working directory as a Path.

func NewPath

func NewPath(s string) *Path

func NewTempDir

func NewTempDir() *Path

NewTempDir returns the temporary directory as a Path.

func NewWorkDir

func NewWorkDir() *Path

NewWorkDir returns the current working directory as a Path.

func (*Path) Absolute

func (p *Path) Absolute() string

Absolute returns the absolute file path for this path.

func (*Path) Append

func (p *Path) Append(s string) *Path

Append a subdirectory or file name[.file extension] to the path. If the string is empty, then '/' will be appended.

func (*Path) Base

func (p *Path) Base() string

Base returns the last component of the path. If the path is empty, "." is returned.

func (*Path) Chmod

func (p *Path) Chmod(mode os.FileMode) error

Chmod changes the mode of the named file to the given mode.

func (*Path) Clean

func (p *Path) Clean() string

Clean cleans up the file path. It returns the absolute file path if needed.

func (*Path) Copy

func (p *Path) Copy() *Path

Copy creates a new copy of the path.

func (*Path) CreateDir

func (p *Path) CreateDir() error

CreateDir assumes that this path represents a directory and creates it along with any parent directories needed as well.

func (*Path) DeleteFile

func (p *Path) DeleteFile() error

DeleteFile assumes that this path represents a file and deletes it.

func (*Path) Expand

func (p *Path) Expand(mapping func(string) string) *Path

Expand replaces ${var} or $var in the given path based on the mapping function returning a new path.

func (*Path) IsPathDir

func (p *Path) IsPathDir() bool

IsPathDir cleans up the supplied file path and then checks the cleaned file path to see if it is an existing standard directory.

func (*Path) IsPathRegularFile

func (p *Path) IsPathRegularFile() bool

IsPathRegularFile cleans up the supplied file path and then checks the cleaned file path to see if it is an existing standard file.

func (*Path) ModTime

func (p *Path) ModTime() time.Time

func (*Path) Mode

func (p *Path) Mode() os.FileMode

func (*Path) RemoveDir

func (p *Path) RemoveDir() error

RemoveDir assumes that this path represents a directory and deletes it along with any parent directories that it can as well.

func (*Path) SetStr

func (p *Path) SetStr(s string)

func (*Path) Size

func (p *Path) Size() int64

Size returns length in bytes for regular files.

func (*Path) String

func (p *Path) String() string

type StringBuilder

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

StringBuilder is a composition of strings.Builder so that we can add supplemental functions such as formatted strings easily.

func NewStringBuilder

func NewStringBuilder() *StringBuilder

func (*StringBuilder) Len

func (s *StringBuilder) Len() int

func (*StringBuilder) String

func (s *StringBuilder) String() string

func (*StringBuilder) WriteString

func (s *StringBuilder) WriteString(format string) error

WriteString allows us to write a string to the buffer.

func (*StringBuilder) WriteStringf

func (s *StringBuilder) WriteStringf(format string, a ...interface{}) error

WriteStringf allows us to write a formatted string.

type WorkQueue

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

WorkQueue represents a one use only structure to execute multiple go routines easily.

func NewWorkQueue

func NewWorkQueue(task func(a interface{}, cmn interface{}), cmn interface{}, s int) *WorkQueue

func (*WorkQueue) CloseAndWaitForCompletion

func (w *WorkQueue) CloseAndWaitForCompletion()

func (*WorkQueue) CloseQueue

func (w *WorkQueue) CloseQueue()

func (*WorkQueue) Complete

func (w *WorkQueue) Complete()

func (*WorkQueue) PushWork

func (w *WorkQueue) PushWork(i interface{})

Jump to

Keyboard shortcuts

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