Documentation ¶
Overview ¶
Package io (input/output) implements auxiliary functions for printing, parsing, handling files, directories, etc.
Index ¶
- Variables
- func AppendToFile(fn string, buffer ...*bytes.Buffer)
- func ArgToBool(idxArg int, defaultValue bool) bool
- func ArgToFilename(idxArg int, fnDefault, ext string, check bool) (filename, fnkey string)
- func ArgToFloat(idxArg int, defaultValue float64) float64
- func ArgToInt(idxArg int, defaultValue int) int
- func ArgToString(idxArg int, defaultValue string) string
- func ArgsTable(title string, data ...interface{}) (table string)
- func Atob(val string) (bres bool)
- func Atof(val string) (res float64)
- func Atoi(val string) (res int)
- func Btoa(flag bool) string
- func Btoi(flag bool) int
- func CopyFileOver(destination, source string)
- func DblSf(msg string, slice []float64) string
- func ExtractStrPair(pair, sep string) (key, val string)
- func Ff(b *bytes.Buffer, msg string, prm ...interface{})
- func FnExt(fn string) string
- func FnKey(fn string) string
- func IntSf(msg string, slice []int) string
- func Itob(val int) bool
- func JoinKeys(keys []string) string
- func JoinKeys3(k0, k1, k2 []string, sep string) (res string)
- func JoinKeys4(k0, k1, k2, k3 []string, sep string) (res string)
- func JoinKeysPre(prefix string, keys []string) (res string)
- func Keycode(String string, Type string) (keycode string, found bool)
- func Keycodes(String string) (keycodes []string)
- func OpenFileR(fn string) (fil *os.File)
- func PathKey(fn string) string
- func Pf(msg string, prm ...interface{})
- func PfBlue(msg string, prm ...interface{})
- func PfCyan(msg string, prm ...interface{})
- func PfGreen(msg string, prm ...interface{})
- func PfMag(msg string, prm ...interface{})
- func PfRed(msg string, prm ...interface{})
- func PfWhite(msg string, prm ...interface{})
- func PfYel(msg string, prm ...interface{})
- func Pfblue(msg string, prm ...interface{})
- func Pfblue2(msg string, prm ...interface{})
- func Pfcyan(msg string, prm ...interface{})
- func Pfcyan2(msg string, prm ...interface{})
- func Pfdgreen(msg string, prm ...interface{})
- func Pfdyel(msg string, prm ...interface{})
- func Pfdyel2(msg string, prm ...interface{})
- func Pfgreen(msg string, prm ...interface{})
- func Pfgreen2(msg string, prm ...interface{})
- func Pfgrey(msg string, prm ...interface{})
- func Pfgrey2(msg string, prm ...interface{})
- func Pflmag(msg string, prm ...interface{})
- func Pfmag(msg string, prm ...interface{})
- func Pforan(msg string, prm ...interface{})
- func Pfpink(msg string, prm ...interface{})
- func Pfpurple(msg string, prm ...interface{})
- func Pfred(msg string, prm ...interface{})
- func Pfyel(msg string, prm ...interface{})
- func Pipeline(cmds ...*exec.Cmd) (pipeLineOutput, collectedStandardError []byte)
- func Pl()
- func ReadFile(fn string) (b []byte)
- func ReadLines(fn string, cb ReadLinesCallback)
- func ReadLinesFile(fil *os.File, cb ReadLinesCallback)
- func ReadMatrix(fn string) (M [][]float64)
- func ReadTable(fn string) (keys []string, T map[string][]float64)
- func RemoveAll(key string)
- func RunCmd(verbose bool, cmd string, args ...string) string
- func Sf(msg string, prm ...interface{}) string
- func SplitFloats(str string) (res []float64)
- func SplitInts(str string) (res []int)
- func SplitKeys(keys string) []string
- func SplitKeys3(res string) (k0, k1, k2 []string)
- func SplitKeys4(res string) (k0, k1, k2, k3 []string)
- func SplitSpacesQuoted(str string) (res []string)
- func SplitWithinParentheses(s string) (res []string)
- func StrSf(msg string, slice []string) string
- func StrSpaces(n int) (l string)
- func StrThickLine(n int) (l string)
- func StrThinLine(n int) (l string)
- func UnColor(msg string) string
- func WriteBytesToFile(fn string, b []byte)
- func WriteBytesToFileD(dirout, fn string, b []byte)
- func WriteBytesToFileVD(dirout, fn string, b []byte)
- func WriteFile(fn string, buffer ...*bytes.Buffer)
- func WriteFileD(dirout, fn string, buffer ...*bytes.Buffer)
- func WriteFileV(fn string, buffer ...*bytes.Buffer)
- func WriteFileVD(dirout, fn string, buffer ...*bytes.Buffer)
- func WriteStringToFile(fn, data string)
- func WriteStringToFileD(dirout, fn, data string)
- func WriteTableVD(dirout, fn string, headers []string, columns ...[]float64)
- type Decoder
- type Encoder
- type ReadLinesCallback
Constants ¶
This section is empty.
Variables ¶
var ( // Verbose activates display of messages on console Verbose = true // ColorsOn activates use of colors on console ColorsOn = true )
Functions ¶
func AppendToFile ¶
AppendToFile appends data to an existent (or new) file
func ArgToBool ¶
ArgToBool parses an argument as a boolean value
Input: idxArg -- index of argument; e.g. 0==first, 1==second, etc. defaultValue -- default value
func ArgToFilename ¶
ArgToFilename parses an argument as a filename
Input: idxArg -- index of argument; e.g. 0==first, 1==second, etc. fnDefault -- default filename; can be "" ext -- the file extension to be added; e.g. ".sim" check -- check for null filename Output: filename -- the filename with extension added fnkey -- filename key == filename without extension Notes: The first first argument may be a file with extension or not. Examples: If the first argument is "simulation.sim" or "simulation" (with ext=".sim") then the results are: filename="simulation.sim" and fnkey="simulation"
func ArgToFloat ¶
ArgToFloat parses an argument as a float64 value
Input: idxArg -- index of argument; e.g. 0==first, 1==second, etc. defaultValue -- default value
func ArgToInt ¶
ArgToInt parses an argument as an integer value
Input: idxArg -- index of argument; e.g. 0==first, 1==second, etc. defaultValue -- default value
func ArgToString ¶
ArgToString parses an argument as a string
Input: idxArg -- index of argument; e.g. 0==first, 1==second, etc. defaultValue -- default value
func ArgsTable ¶
ArgsTable prints a nice table with input arguments
Input: title -- title of table; e.g. INPUT ARGUMENTS data -- sets of THREE items in the following order: description, key, value, ... description, key, value, ... ... description, key, value, ...
func CopyFileOver ¶
func CopyFileOver(destination, source string)
CopyFileOver copies file (Linux only with cp), overwriting if it exists already
func ExtractStrPair ¶
ExtractStrPair extracts the pair from, e.g., "key:val"
Note: it returns empty strings if any is not found
func FnExt ¶
FnExt returns the extension of a file name. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.
func Itob ¶
Itob converts from integer to bool
Note: only zero returns false anything else returns true
func JoinKeys3 ¶
JoinKeys3 joins keys from 3 slices into a string with sets separated by sep and keys separeted by spaces
func JoinKeys4 ¶
JoinKeys4 joins keys from 4 slices into a string with sets separated by sep and keys separeted by spaces
func JoinKeysPre ¶
JoinKeysPre join keys separeted by spaces with a prefix
func Keycode ¶
Keycode extracts a keycode from a string such as "!typeA:keycodeA !typeB:keycodeB!typeC:keycodeC"
Note: String == "!keyA !typeB:valB" is also valid
func Keycodes ¶
Keycodes extracts keys from a keycode (extra) string
Example: "!keyA !typeB:valB" => keycodes = [keyA, typeB]
func PfBlue ¶
func PfBlue(msg string, prm ...interface{})
PfBlue prints formatted string in high intensity blue
func PfCyan ¶
func PfCyan(msg string, prm ...interface{})
PfCyan prints formatted string in high intensity cyan
func PfGreen ¶
func PfGreen(msg string, prm ...interface{})
PfGreen prints formatted string in high intensity green
func PfMag ¶
func PfMag(msg string, prm ...interface{})
PfMag prints formatted string in high intensity magenta
func PfRed ¶
func PfRed(msg string, prm ...interface{})
PfRed prints formatted string in high intensity red
func PfWhite ¶
func PfWhite(msg string, prm ...interface{})
PfWhite prints formatted string in high intensity white
func PfYel ¶
func PfYel(msg string, prm ...interface{})
PfYel prints formatted string in high intensity yellow
func Pfblue2 ¶
func Pfblue2(msg string, prm ...interface{})
Pfblue2 prints formatted string in another shade of blue
func Pfcyan2 ¶
func Pfcyan2(msg string, prm ...interface{})
Pfcyan2 prints formatted string in another shade of cyan
func Pfdgreen ¶
func Pfdgreen(msg string, prm ...interface{})
Pfdgreen prints formatted string in dark green
func Pfdyel ¶
func Pfdyel(msg string, prm ...interface{})
Pfdyel prints formatted string in dark yellow
func Pfdyel2 ¶
func Pfdyel2(msg string, prm ...interface{})
Pfdyel2 prints formatted string in another shade of dark yellow
func Pfgreen ¶
func Pfgreen(msg string, prm ...interface{})
Pfgreen prints formatted string in green
func Pfgreen2 ¶
func Pfgreen2(msg string, prm ...interface{})
Pfgreen2 prints formatted string in another shade of green
func Pfgrey2 ¶
func Pfgrey2(msg string, prm ...interface{})
Pfgrey2 prints formatted string in another shade of grey
func Pflmag ¶
func Pflmag(msg string, prm ...interface{})
Pflmag prints formatted string in light magenta
func Pfpurple ¶
func Pfpurple(msg string, prm ...interface{})
Pfpurple prints formatted string in purple
func Pipeline ¶
Pipeline strings together the given exec.Cmd commands in a similar fashion to the Unix pipeline. Each command's standard output is connected to the standard input of the next command, and the output of the final command in the pipeline is returned, along with the collected standard error of all commands and the first error found (if any).
by Kyle Lemons
To provide input to the pipeline, assign an io.Reader to the first's Stdin.
func ReadLines ¶
func ReadLines(fn string, cb ReadLinesCallback)
ReadLines reads lines from a file and calls ReadLinesCallback to process each line being read
func ReadLinesFile ¶
func ReadLinesFile(fil *os.File, cb ReadLinesCallback)
ReadLinesFile reads lines from a file and calls ReadLinesCallback to process each line being read
func ReadMatrix ¶
ReadMatrix reads a text file in which the float64 type of numeric values represent a matrix of data. The number of columns must be equal, including for the headers
func ReadTable ¶
ReadTable reads a text file in which the first line contains the headers and the next lines the float64 type of numeric values. The number of columns must be equal, including for the headers
func RemoveAll ¶
func RemoveAll(key string)
RemoveAll deletes all files matching filename specified by key (be careful)
func SplitFloats ¶
SplitFloats splits space-separated float numbers
func SplitKeys3 ¶
SplitKeys3 splits a string with three sets of keys separated by comma
func SplitKeys4 ¶
SplitKeys4 splits a string with four sets of keys separated by comma
func SplitSpacesQuoted ¶
SplitSpacesQuoted splits string with quoted substrings. e.g. " a,b, 'c', \"d\" "
func SplitWithinParentheses ¶
SplitWithinParentheses extracts arguments (substrings) within brackets e.g.: "(arg1, (arg2.1, arg2.2), arg3, arg4, (arg5.1,arg5.2, arg5.3 ) )"
func StrThickLine ¶
StrThickLine returns a thick line (using '=')
func WriteBytesToFile ¶
WriteBytesToFile writes slice of bytes to a new file
func WriteBytesToFileD ¶
WriteBytesToFileD writes slice of bytes to a new file after creating a directory
func WriteBytesToFileVD ¶
WriteBytesToFileVD writes slice of bytes to a new file, and print message, after creating a directory
func WriteFileD ¶
WriteFileD writes data to a new file after creating a directory
func WriteFileV ¶
WriteFileV writes data to a new file, and shows message
func WriteFileVD ¶
WriteFileVD writes data to a new file, and shows message after creating a directory
func WriteStringToFile ¶
func WriteStringToFile(fn, data string)
WriteStringToFile writes string to a new file
func WriteStringToFileD ¶
func WriteStringToFileD(dirout, fn, data string)
WriteStringToFileD writes string to a new file after creating a directory
func WriteTableVD ¶ added in v1.2.1
WriteTableVD writes a text file in which the first line contains the headers, and the next lines contain the numeric values (float64). The number of columns must be equal to the number of headers.
Types ¶
type Decoder ¶ added in v1.2.1
type Decoder interface {
Decode(e interface{}) error
}
Decoder defines decoders; e.g. gob or json
type Encoder ¶ added in v1.2.1
type Encoder interface {
Encode(e interface{}) error
}
Encoder defines encoders; e.g. gob or json
type ReadLinesCallback ¶
ReadLinesCallback is used in ReadLines to process line by line during reading of a file