modulepackage
0.0.0-20250114120308-5f4c15c68819
Repository: https://github.com/ungerik/go-dry.git
Documentation: pkg.go.dev
# README
go-dry
-DRY (don't repeat yourself) package for Go
-Documentation: http://godoc.org/github.com/ungerik/go-dry
# Functions
AsError returns r as error, converting it when necessary.
AsErrorList checks if err is already an ErrorList and returns it if this is the case.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BytesFilter filters out all bytes where the function does not return true.
No description provided by the author
BytesHead returns at most numLines from data starting at the beginning.
No description provided by the author
BytesMap maps a function on each element of a slice of bytes.
No description provided by the author
No description provided by the author
BytesTail returns at most numLines from the end of data.
No description provided by the author
DecryptAES decrypts ciphertext using AES with the given key.
EncryptAES encrypts plaintext using AES with the given key.
No description provided by the author
No description provided by the author
No description provided by the author
EnvironMap returns the current environment variables as a map.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FileCopy copies file source to destination dest.
FileCopyDir recursively copies a directory tree, attempting to preserve permissions.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FileGetLastLine reads the last line from a file.
FileGetLines returns a string slice with the text lines of filenameOrURL.
FileGetNonEmptyLines returns a string slice with the non empty text lines of filenameOrURL.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FileSize returns the size of a file or zero in case of an error.
FileTimeModified returns the modified time of a file, or the zero time value in case of an error.
No description provided by the author
No description provided by the author
No description provided by the author
FirstArg returns the first passed argument, can be used to extract first result value from a function call to pass it on to functions like fmt.Printf.
FirstError returns the first non nil error, or nil.
GetenvDefault retrieves the value of the environment variable named by the key.
GetError returns the last argument that is of type error, panics if none of the passed args is of type error.
HTTPCompressHandlerFunc wraps a http.HandlerFunc so that the response gets gzip or deflate compressed if the Accept-Encoding header of the request allows it.
HTTPDelete performs a HTTP DELETE request.
HTTPPostForm performs a HTTP POST request with data as application/x-www-form-urlencoded.
HTTPPostJSON marshalles data as JSON and sends it as HTTP POST request to url.
HTTPPostXML marshalles data as XML and sends it as HTTP POST request to url.
HTTPPutForm performs a HTTP PUT request with data as application/x-www-form-urlencoded.
HTTPRespondMarshalIndentJSON marshals response as JSON to responseWriter, sets Content-Type to application/json and compresses the response if Content-Encoding from the request allows it.
HTTPRespondMarshalIndentXML marshals response as XML to responseWriter, sets Content-Type to application/xml and compresses the response if Content-Encoding from the request allows it.
HTTPRespondMarshalJSON marshals response as JSON to responseWriter, sets Content-Type to application/json and compresses the response if Content-Encoding from the request allows it.
HTTPRespondMarshalXML marshals response as XML to responseWriter, sets Content-Type to application/xml and compresses the response if Content-Encoding from the request allows it.
HTTPRespondText sets Content-Type to text/plain and compresses the response if Content-Encoding from the request allows it.
HTTPUnmarshalRequestBodyJSON reads a http.Request body and unmarshals it as JSON to result.
InterfaceSlice converts a slice of any type into a slice of interface{}.
No description provided by the author
LastError returns the last non nil error, or nil.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NetIP returns the primary IP address of the system or an empty string.
NewErrorList returns an ErrorList where Collect has been called for args.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Nop is a dummy function that can be called in source files where other debug functions are constantly added and removed.
PanicIfErr panics with a stack trace if any of the passed args is a non nil error.
PrettyPrintAsJSON marshalles input as indented JSON and calles fmt.Println with the result.
RandomHexString returns a random lower case hex string with length.
RandomHEXString returns a random upper case hex string with length.
RandSeedWithTime calls rand.Seed() with the current time.
ReadBinary wraps binary.Read with a CountingReader and returns the acutal bytes read by it.
ReadLine reads unbuffered until a newline '\n' byte and removes an optional carriege return '\r' at the end of the line.
RealNetIP returns the real local IP of the system or an empty string.
ReflectExportedStructFields returns a map from exported struct field names to values,
inlining anonymous sub-structs so that their field names are available
at the base level.
No description provided by the author
ReflectSetStructFieldsFromStringMap sets the fields of a struct with the field names and values taken from a map[string]string.
ReflectSetStructFieldString sets the field with name to value.
ReflectSort will sort slice according to compareFunc using reflection.
No description provided by the author
ReflectTypeOfError returns the built-in error type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Filter out all strings where the function does not return true.
StringFind returns in found if token has been found in s, and returns the remaining string afte token in remainder.
StringFindBetween returns the string between the first occurrences of the tokens start and stop.
No description provided by the author
No description provided by the author
No description provided by the author
StringJoin formats every value in values according to its default formatting and joins the result with sep as separator.
StringJoinFormat formats every value in values with format and joins the result with sep as separator.
No description provided by the author
No description provided by the author
Map a function on each element of a slice of strings.
No description provided by the author
No description provided by the author
No description provided by the author
StringMarshalJSON marshals data to an indented string.
StringMD5Hex returns the hex encoded MD5 hash of data.
No description provided by the author
StringReplaceHTMLTags replaces HTML/XML tags from text with replacement.
No description provided by the author
StringSHA1Base64 returns the base64 encoded SHA1 hash of data.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StringStripHTMLTags strips HTML/XML tags from text.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TwoSlicesSubtraction remove any string that A,B both contain from A and returns the remainder of A.
WaitForStdin blocks until input is available from os.Stdin.
WriteFull calls writer.Write until all of data is written, or an is error returned.
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
DebugMutex wraps a sync.Mutex and adds debug output.
DebugRWMutex wraps a sync.RWMutex and adds debug output.
DeflatePool manages a pool of flate.Writer flate.NewWriter allocates a lot of memory, so if flate.Writer are needed frequently, it's more efficient to use a pool of them.
FileCopyError is a struct for returning file copy error messages.
GzipPool manages a pool of gzip.Writer.
HTTPCompressHandler wraps a http.Handler so that the response gets gzip or deflate compressed if the Accept-Encoding header of the request allows it.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
ErrorList holds a slice of errors.
ReaderFunc implements io.Reader as function type with a Read method.
No description provided by the author
StringSet wraps map[string]struct{} with some useful methods.
WriterFunc implements io.Writer as function type with a Write method.