goutility

package module
v0.0.0-...-6542a44 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2017 License: MIT Imports: 14 Imported by: 0

README

goutility

CircleCI TravisCI Go Report Card codebeat badge Coverage Status

Poursteady's general golang utility library

Documentation

Index

Constants

View Source
const (
	UnspecifiedCode        = -1
	UnspecifiedCodeContext = "goutility"
)

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src string, dst string) (err error)

CopyFile copy a file from src to dst

func CreatePathIfDoesNotExist

func CreatePathIfDoesNotExist(path string) (bool, error)

CreatePathIfDoesNotExist ensures the path exists, even if it has to create it. Returns an error if there was a problem checking that the path exists or creating the path. Returns true if the path had to be created, false if the path already existed.

func CurrentExecutable

func CurrentExecutable() string

CurrentExecutable return the name of the current executable

func EmitOnChan

func EmitOnChan(c chan string) func(string) error

EmitOnChan emit values through a channel, drain the channel if we're full

func FileExists

func FileExists(path string) (bool, error)

FileExists check if a file exists

func FirstCharacter

func FirstCharacter(in string) string

FirstCharacter return the first character in a string

func GetAvailableIPFromAddress

func GetAvailableIPFromAddress(address net.Addr) net.IP

GetAvailableIPFromAddress retrieves the IP from a net.Addr if one is available

func GetFirstNonLoopbackIP

func GetFirstNonLoopbackIP() (string, error)

GetFirstNonLoopbackIP get first non-loopback ip address of the current machine

func GetStack

func GetStack() []byte

func NewError

func NewError(format string, parameters ...interface{}) error

NewError make a new error using SPrintf TODO: deprecate in favor of Error

func NowFileString

func NowFileString() string

NowFileString the current date and time as a file name safe string

func PadStringToLength

func PadStringToLength(original string, padWith string, length int) string

PadStringToLength pad string with string until it is equal to or greater than length param and return the result

func PathStrippedOfQuery

func PathStrippedOfQuery(path string) string

PathStrippedOfQuery return the path minus any query

func PrintBeforeAndAfterStacks

func PrintBeforeAndAfterStacks(before []byte, after []byte, t *testing.T)

func RandomString

func RandomString(length int) string

RandomString create a random string of specified length

func SprintfObject

func SprintfObject(i interface{}, contents bool) (result string)

SprintfObject print information about an object to a string, optionally include its contents

func SprintfObjectContents

func SprintfObjectContents(i interface{}) (result string, error error)

SprintfObjectContents print contents of an object to a string

func SprintfObjectInstance

func SprintfObjectInstance(i interface{}) string

SprintfObjectInstance print information about an object to a string

func StringAppendWithJoin

func StringAppendWithJoin(left string, join string, right string) (result string)

StringAppendWithJoin append two strings with a join string accounting for empty strings

func StringOfStringRepeated

func StringOfStringRepeated(component string, count int) string

StringOfStringRepeated return a string composed of component repeated count times

Types

type ErrorCode

type ErrorCode int
const (
	CodeContext = "goutility"

	UnableToFindExternalIPAddressErrorCode ErrorCode = 1 << iota

	MarshalErrorCode
	UnmarshalErrorCode
)

type ErrorType

type ErrorType struct {
	// contains filtered or unexported fields
}

func MakeError

func MakeError(message string) ErrorType

func MakeErrorWithCode

func MakeErrorWithCode(message string, code ErrorCode, codeContext string) ErrorType

func (ErrorType) Code

func (this ErrorType) Code() ErrorCode

func (ErrorType) CodeContext

func (this ErrorType) CodeContext() string

func (ErrorType) Error

func (this ErrorType) Error() string

func (ErrorType) HasValidCode

func (this ErrorType) HasValidCode() bool

func (ErrorType) Message

func (this ErrorType) Message() string

type ErrorTypeInterface

type ErrorTypeInterface interface {
	Error() string

	Message() string

	Code() ErrorCode

	CodeContext() string

	HasValidCode() bool
}

func MarshalIndentToJSON

func MarshalIndentToJSON(v interface{}, prefix string, indent string) ([]byte, ErrorTypeInterface)

func MarshalToJSON

func MarshalToJSON(v interface{}) ([]byte, ErrorTypeInterface)

func ReadFile

func ReadFile(filename string) ([]byte, ErrorTypeInterface)

func ReadObjectFromJSONFile

func ReadObjectFromJSONFile(object interface{}, fileName string) ErrorTypeInterface

ReadObjectFromJSONFile read an object from a JSON file

func UnmarshalFromJSON

func UnmarshalFromJSON(data []byte, v interface{}) ErrorTypeInterface

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) ErrorTypeInterface

func WriteObjectToJSONFile

func WriteObjectToJSONFile(object interface{}, fileName string, pretty bool) ErrorTypeInterface

WriteObjectToJSONFile write an object to a JSON file

type JSONSafeTime

type JSONSafeTime struct {
	time.Time
}

func (*JSONSafeTime) Format

func (this *JSONSafeTime) Format() string

func (*JSONSafeTime) MarshalJSON

func (this *JSONSafeTime) MarshalJSON() ([]byte, error)

func (*JSONSafeTime) UnmarshalJSON

func (this *JSONSafeTime) UnmarshalJSON(b []byte) (err error)

type MashalError

type MashalError struct {
	ErrorType
	// contains filtered or unexported fields
}

region MashalError

func MakeMashalError

func MakeMashalError(object interface{}, error error) MashalError

type ReadFileError

type ReadFileError struct {
	ErrorType
	// contains filtered or unexported fields
}

region ReadFileError

func MakeReadFileError

func MakeReadFileError(filePath string, error error) ReadFileError

type UnableToFindExternalIPAddressError

type UnableToFindExternalIPAddressError struct {
	ErrorType
}

region UnableToFindExternalIPAddressError

func MakeUnableToFindExternalIPAddressError

func MakeUnableToFindExternalIPAddressError() UnableToFindExternalIPAddressError

type UnmarshalError

type UnmarshalError struct {
	ErrorType
	// contains filtered or unexported fields
}

region UnmarshalError

func MakeUnmashalError

func MakeUnmashalError(object interface{}, error error) UnmarshalError

type WriteFileError

type WriteFileError struct {
	ErrorType
	// contains filtered or unexported fields
}

region WriteFileError

func MakeWriteFileError

func MakeWriteFileError(filePath string, error error) WriteFileError

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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