Documentation ¶
Index ¶
- func CdBack(backDir string)
- func CdToThis()
- func ErrorContains(out error, want string) bool
- func FileSize(filepath string) (int64, error)
- func LogError(err error)
- func MakeRange(start, end int) []int
- func MinMax(array []int) (int, int)
- func MinMaxFloat64(array []float64) (float64, float64)
- func ReadAllLn(filepath string, keepBreakLine bool) ([]string, error)
- func StringInSlice(a string, list []string) bool
- func StringIndex(s, sub string) (index int, err error)
- func ToASCII(s string) string
- func ToGrapheme(s string) string
- func TraceError(err error) error
- func Zip(a, b, c interface{}) error
- type Iter
- type RuneGen
- type RuneIter
- type RuneReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CdToThis ¶
func CdToThis()
CdToThis changes `working directory` to the current directory of function that calls it.
A use case is when a function at coding file reads a relative file, however the end user, at run time, executes the coding file at a different directory to the coding file. As relative path has been used, one would change from any directory at run time to `current` directory where function is called to get the correct relative path.
Example: There a Go package in a os directory as follow:
- os-home | +--go-package | | | +--data | | | | | +--data-file.txt | | | +--sub-package | | | +--go-file.go | +--other-folder
There's a function `ReadData` in `go-file.go` that read a data file `data-file.txt` in other directory using a relative filepath to its - I.e: "../data/data-file.txt". Now, a end user run `go-file.go` from `other-folder` directory which is not at the same directory to `go-file.go` file. `ReadData` function would be panic if there was no helper to change directory from directory where end user executes the code ("os-home/other-folder") to directory of `go-file.go`. `CdToThis` does this job.
func ErrorContains ¶
ErrorContains checks if the error message in out contains the text in want Ref. https://stackoverflow.com/questions/42035104
Example usage if !ErrorContains(err, "unexpected banana") { t.Errorf("unexpected error: %v", err) }
if !ErrorContains(err, "") { t.Errorf("unexpected error: %v", err) }
func FileSize ¶
FileSize returns length of given file using `os.Stat()` Ref. https://stackoverflow.com/questions/17133590
func MakeRange ¶
* // Makerange creates a sequence of number (range) * // Ref. https://stackoverflow.com/questions/39868029 * func MakeRange(min, max int) []int { * if min == max { * return []int{} * } * a := make([]int, max-min+1) * for i := range a { * a[i] = min + i * } * return a * } *
func MinMaxFloat64 ¶
MinMax returns min and max from input int array
func StringInSlice ¶
StringInSlice check whether given string is in a slice
func StringIndex ¶
StringIndex returns index (start) for substring on a given string It returns -1 and error if not matching
func ToASCII ¶
ToASCII converts string to ASCII form Ref. https://stackoverflow.com/questions/12668681
func ToGrapheme ¶
ToGrapheme converts string to grapheme TODO: should we include this func? Ref: https://github.com/golang/go/issues/14820
func TraceError ¶
HandleError wraps original error message with function and source code position where error is captured. Ref. https://stackoverflow.com/questions/24809287
func Zip ¶
func Zip(a, b, c interface{}) error
Zip zips 2 slices in first and second arguments to third argument Ref: https://stackoverflow.com/questions/26957040
Usage Example a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0} b := []int{0, 9, 8, 7, 6, 5, 4, 3, 2, 1} c := [][2]int{}
e := zip(a, b, &c)
if e != nil { fmt.Println(e) return }
fmt.Println(c)
Types ¶
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
Iter contains data and methods for an interator
type RuneIter ¶
type RuneIter struct {
// contains filtered or unexported fields
}
RuneIter is rune iterator with Next() method.
func (*RuneIter) CurrentIndex ¶
CurrentIndex returns current index of RuneIter
type RuneReader ¶
type RuneReader struct {
// contains filtered or unexported fields
}
func NewRuneReader ¶
func NewRuneReader(r []rune) RuneReader
NewRuneReader create a new of type `io.RuneReader`