Documentation ¶
Overview ¶
Package utils is a collection of helpful utilities for common actions within GoLang development
Index ¶
- func CorsHandler(handler http.Handler) http.Handler
- func GenerateSlug(str string) (slug string)
- func InChain(needle string, haystack []string) bool
- func IsEmpty(val reflect.Value) bool
- func Update(mainObj interface{}, newData interface{}) bool
- func Without(arr []string, remove string) (chopped []string)
- type ApiResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorsHandler ¶
func CorsHandler provides an *extremely* broad Cors handler for development Not suitable for production use, as origin, method, and headers should all be more extensively restricted for a production environment
func GenerateSlug ¶
GenerateSlug converts a string into a lowercase dasherized slug
For example: GenerateSlug("My cool object") returns "my-cool-object"
func InChain ¶
InChain returns a boolean if a string is already in a slice of strings
[TODO] Extend this to work for all standard types
func IsEmpty ¶
IsEmpty checks to see if a field has a set value
Goes beyond usual reflect.IsZero check to handle numbers, strings, and slices For structs, iterates over all accessible properties and returns true only if all nested fields are also empty.
Types ¶
type ApiResponse ¶
type ApiResponse struct { Code int `json:"code"` Message string `json:"message"` Result interface{} `json:"result"` Data map[string]interface{} `json:"data"` // Generic extra data to be sent along in response }
type ApiResponse is a generic API response struct