package module
v0.1.0 Latest Latest

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

Go to latest
Published: Mar 10, 2016 License: Apache-2.0 Imports: 15 Imported by: 544


Gotil GoDoc Build Status Go Report Card Coverage Status

Gotil provides many common, helpful utilities to other golang projects. Examples include determining if a string exists in a slice of strings, parsing a network address, getting a channel that returns lines from a buffer or file, and more!

Please see gotil_test.go for a list of all the utilities, including how to use them.




This section is empty.


This section is empty.


func FileExists

func FileExists(filePath string) bool

FileExists returns a flag indicating whether a provided file path exists.

func FileExistsInPath

func FileExistsInPath(fileName string) bool

FileExistsInPath returns a flag indicating whether the provided file exists in the current path.

func GetLocalIP

func GetLocalIP() (ip string)

GetLocalIP returns the non loopback local IP of the host

func GetPathParts

func GetPathParts(path string) (dirPath, fileName, absPath string)

GetPathParts returns the absolute directory path, the file name, and the absolute path of the provided path string.

func GetThisPathParts

func GetThisPathParts() (dirPath, fileName, absPath string)

GetThisPathParts returns the same information as GetPathParts for the current executable.

func HomeDir

func HomeDir() string

HomeDir returns the home directory of the user that owns the current process.

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

IsDirEmpty returns a flag indicating whether or not a directory has any child objects such as files or directories in it.

func IsTCPPortAvailable

func IsTCPPortAvailable(port int) bool

IsTCPPortAvailable returns a flag indicating whether or not a TCP port is available.

func LineReader

func LineReader(r io.Reader) (<-chan string, error)

LineReader returns a channel that reads the contents of a reader line-by-line.

func LineReaderFrom

func LineReaderFrom(path string) (<-chan string, error)

LineReaderFrom returns a channel that reads the contents of a file line-by-line.

func ParseAddress

func ParseAddress(addr string) (proto string, path string, err error)

ParseAddress parses a standard golang network address and returns the protocol and path.

func RandomString

func RandomString(length int) string

RandomString generates a random set of characters with the given lenght.

func RandomTCPPort

func RandomTCPPort() int

RandomTCPPort gets a free, random TCP port between 1025-65535. If no free ports are available -1 is returned.

func ReadFileToString

func ReadFileToString(path string) (string, error)

ReadFileToString reads the file at the provided path to a string.

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice returns a flag indicating whether or not a provided string exists in a string slice. The string comparison is case-insensitive.

func StringInSliceCS

func StringInSliceCS(a string, list []string) bool

StringInSliceCS returns a flag indicating whether or not a provided string exists in a string slice. The string comparison is case-sensitive.

func Trim

func Trim(text string) string

Trim removes all leading and trailing whitespace, including tab, newline, and carriage return characters.

func WriteIndented

func WriteIndented(w io.Writer, b []byte) error

WriteIndented indents all lines four spaces.

func WriteIndentedN

func WriteIndentedN(w io.Writer, b []byte, n int) error

WriteIndentedN indents all lines n spaces.

func WriteStringToFile

func WriteStringToFile(text, path string) error

WriteStringToFile writes the string to the file at the provided path.


This section is empty.

Jump to

Keyboard shortcuts

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