util

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 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 NewCurrentWorkDir added in v1.0.3

func NewCurrentWorkDir() *Path

NewCurrentWorkDir returns the current working directory as a Path.

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 (*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) Dir added in v1.0.3

func (p *Path) Dir() string

Dir returns everything but the last component of the path. If the directory portion is empty, then '.' is returned.

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 SharedData added in v1.0.1

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

SharedData represents a common structure to share data across packages easily. It would normally be created in package, main, and passed as needed to other packages.

func (*SharedData) Cmd added in v1.0.1

func (s *SharedData) Cmd() string

func (*SharedData) DataPath added in v1.0.1

func (s *SharedData) DataPath() string

DataPath is the path to the app json file.

func (*SharedData) Debug added in v1.0.1

func (s *SharedData) Debug() bool

func (*SharedData) Defn added in v1.0.1

func (s *SharedData) Defn(nm string) interface{}

func (*SharedData) Force added in v1.0.1

func (s *SharedData) Force() bool

func (*SharedData) Funcs added in v1.0.1

func (s *SharedData) Funcs() map[string]interface{}

func (*SharedData) FuncsSlice added in v1.0.1

func (s *SharedData) FuncsSlice() []interface{}

func (*SharedData) GenDebugging added in v1.0.1

func (s *SharedData) GenDebugging() bool

func (*SharedData) GenLogging added in v1.0.1

func (s *SharedData) GenLogging() bool

func (*SharedData) GenMuxWrapper added in v1.0.1

func (s *SharedData) GenMuxWrapper() bool

func (*SharedData) Init added in v1.0.1

func (s *SharedData) Init()

func (*SharedData) IsDefined added in v1.0.1

func (s *SharedData) IsDefined(nm string) bool

func (*SharedData) MainPath added in v1.0.1

func (s *SharedData) MainPath() string

MainPath is the path to the main json file.

func (*SharedData) MergeFrom added in v1.0.1

func (s *SharedData) MergeFrom(m map[string]interface{}, rep bool)

MergeFrom merges the given map into the shared data definitions optionally replacing any that already exist.

func (*SharedData) MergeTo added in v1.0.1

func (s *SharedData) MergeTo(m map[string]interface{}, rep bool)

MergeTo merges the shared into the given map optionally replacing any in the given map.\

func (*SharedData) Noop added in v1.0.1

func (s *SharedData) Noop() bool

func (*SharedData) OutDir added in v1.0.1

func (s *SharedData) OutDir() string

func (*SharedData) Quiet added in v1.0.1

func (s *SharedData) Quiet() bool

func (*SharedData) Replace added in v1.0.1

func (s *SharedData) Replace() bool

func (*SharedData) SetCmd added in v1.0.1

func (s *SharedData) SetCmd(f string)

func (*SharedData) SetDataPath added in v1.0.1

func (s *SharedData) SetDataPath(f string)

func (*SharedData) SetDebug added in v1.0.1

func (s *SharedData) SetDebug(f bool)

func (*SharedData) SetDefn added in v1.0.1

func (s *SharedData) SetDefn(nm string, d interface{})

func (*SharedData) SetForce added in v1.0.1

func (s *SharedData) SetForce(f bool)

func (*SharedData) SetFunc added in v1.0.1

func (s *SharedData) SetFunc(nm string, d interface{})

func (*SharedData) SetMainPath added in v1.0.1

func (s *SharedData) SetMainPath(f string)

func (*SharedData) SetNoop added in v1.0.1

func (s *SharedData) SetNoop(f bool)

func (*SharedData) SetOutDir added in v1.0.1

func (s *SharedData) SetOutDir(f string)

func (*SharedData) SetQuiet added in v1.0.1

func (s *SharedData) SetQuiet(f bool)

func (*SharedData) SetReplace added in v1.0.1

func (s *SharedData) SetReplace(f bool)

func (*SharedData) SetTime added in v1.0.1

func (s *SharedData) SetTime(f string)

func (*SharedData) String added in v1.0.1

func (s *SharedData) String() string

String returns a stringified version of the shared data

func (*SharedData) Time added in v1.0.1

func (s *SharedData) Time() string

MainPath is the path to the main json file.

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