util

package
Version: v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPublicIP

func DetectPublicIP() (*string, error)

DetectPublicIP detects your public IP address and returns a pointer to a string containing the IP address or any error

func EnsureFile

func EnsureFile(path, contents string) (bool, error)

EnsureFile checks a file exists and writes the supplied contents if not. returns a boolean indicating whether it wrote a file or not and any error

func EnvOrDefault

func EnvOrDefault(key, def string) string

EnvOrDefault tries to read an environment variable with the supplied key and returns its value. EnvOrDefault returns a default value if it is empty or unset

func ExpandTilde

func ExpandTilde(path string) (*string, error)

ExpandTilde returns the fully qualified path to a file in the user's home directory. I.E. it expands a path beginning with `~/`) and checks the file exists. ExpandTilde will cache the user's home directory to amortise the cost of the syscall

func FileExists

func FileExists(path string) (bool, error)

FileExists checks whether a path exists

func IsStringInSlice added in v0.6.0

func IsStringInSlice(a string, list []string) (bool, error)

IsStringInSlice checks if string a apperas in list list and returns a boolean and error if it isn't present in string

func MustRemove

func MustRemove(path string)

MustRemove removes a file or empty directory. MustRemove will ignore an error if the path doesn't exist or panic for any other error

func MustSlurp

func MustSlurp(path string) string

MustSlurp is the panicky counterpart to Slurp. MustSlurp reads an entire file into a string in one operation and returns the contents or panics if it encouters and error

func OverwriteFile

func OverwriteFile(path, contents string) error

OverwriteFile writes the supplied contents overwriting the path if it already exists. It returns an error if any occurred

func Slurp

func Slurp(path string) (*string, error)

Slurp reads an entire file into a string in one operation and returns a pointer to the file's content or an error if any. Similar to `ioutil.ReadFile` but it calls `filepath.Abs` first which cleans the path and resolves relative paths from the working directory.

Note that this is slightly less efficient for zero-length files than `ioutil.Readfile` as it uses the default read buffer size of `bytes.MinRead` internally

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL