Documentation ¶
Overview ¶
Go programming helpers for common miscellaneous needs.
Index ¶
- Variables
- func GoPaths() []string
- func GopathSrc(subDirNames ...string) (gps string)
- func GopathSrcGithub(gitHubName string, subDirNames ...string) string
- func HostName() (hostName string)
- func Ifb(cond, ifTrue, ifFalse bool) bool
- func Ifd(cond bool, ifTrue, ifFalse float64) float64
- func Ifi(cond bool, ifTrue, ifFalse int) int
- func Ifi16(cond bool, ifTrue, ifFalse int16) int16
- func Ifi32(cond bool, ifTrue, ifFalse int32) int32
- func Ifi64(cond bool, ifTrue, ifFalse int64) int64
- func Ifs(cond bool, ifTrue string, ifFalse string) string
- func Ifu32(cond bool, ifTrue, ifFalse uint32) uint32
- func Ifu64(cond bool, ifTrue, ifFalse uint64) uint64
- func Ifw(cond bool, ifTrue, ifFalse io.Writer) io.Writer
- func Ifx(cond bool, ifTrue, ifFalse interface{}) interface{}
- func LogError(err error)
- func MaxProcs()
- func OSName(goOS string) (name string)
- func ParseVersion(verstr string) (majorMinor [2]int, both float64)
- func UserHomeDirPath() (dirPath string)
- type MutexIf
Constants ¶
This section is empty.
Variables ¶
var ( // The string format used in LogError(). LogErrorFormat = "%v" // Look-up hash-table for the `OSName` function. OSNames = map[string]string{ "windows": "Windows", "darwin": "Mac OS X", "linux": "Linux", "freebsd": "FreeBSD", "appengine": "Google App Engine", } )
Functions ¶
func GoPaths ¶
func GoPaths() []string
Returns all paths listed in the `GOPATH` environment variable.
func GopathSrc ¶
Returns the `path/filepath.Join`-ed full directory path for a specified `$GOPATH/src` sub-directory. Example: `util.GopathSrc("tools", "importers", "sql")` yields `c:\gd\src\tools\importers\sql` if `$GOPATH` is `c:\gd`.
func GopathSrcGithub ¶
Returns the `path/filepath.Join`-ed full directory path for a specified `$GOPATH/src/github.com` sub-directory. Example: `util.GopathSrcGithub("go-utils", "unum")` yields `c:\gd\src\github.com\go-utils\unum` if `$GOPATH` is `c:\gd`.
func HostName ¶
func HostName() (hostName string)
Returns the result of `os.Hostname` if any, else `localhost`.
func Ifx ¶
func Ifx(cond bool, ifTrue, ifFalse interface{}) interface{}
Returns `ifTrue` if `cond` is `true`, otherwise returns `ifFalse`.
func LogError ¶
func LogError(err error)
A convenience short-hand for `log.Println(fmt.Sprintf(LogErrorFormat, err))` if `err` isn't `nil`.
func OSName ¶
Returns the human-readable operating system name represented by the specified `goOS` name, by looking up the corresponding entry in `OSNames`.
func ParseVersion ¶
Attempts to extract major and minor version components from a string that begins with a version number. Example: returns []int{3, 2} and float64(3.2) for a `verstr` that is `3.2.0 - Build 8.15.10.2761`.
func UserHomeDirPath ¶
func UserHomeDirPath() (dirPath string)
Returns the path to the current user's home directory. Might be `C:\Users\Kitty` under Windows, `/home/Kitty` under Linux or `/Users/Kitty` under Mac OS X. Specifically, returns the value of either the `%userprofile%` (Windows) or the `$HOME` (others) environment variable, whichever one is set.