package module
v0.0.0-...-84173ec Latest Latest

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

Go to latest
Published: Dec 7, 2014 License: MIT Imports: 5 Imported by: 3


GoLang Utilities

A collection of utilities I've found useful during my GoLang development. Feel free to submit bugs or PRs to make these more useful.

Full documentation at: GoDoc



Package utils is a collection of helpful utilities for common actions within GoLang development



This section is empty.


This section is empty.


func CorsHandler

func CorsHandler(handler http.Handler) http.Handler

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

func GenerateSlug(str string) (slug string)

GenerateSlug converts a string into a lowercase dasherized slug

For example: GenerateSlug("My cool object") returns "my-cool-object"

func InChain

func InChain(needle string, haystack []string) bool

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

func IsEmpty(val reflect.Value) bool

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.

func Update

func Update(mainObj interface{}, newData interface{}) bool

Similar to "extend" in JS, only updates fields that are specified and not empty in newData

Both newData and mainObj must be pointers to struct objects

func Without

func Without(arr []string, remove string) (chopped []string)

Without returns a copy of the slice without the remove parameter

[TODO] Extend to work with all standard 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

Jump to

Keyboard shortcuts

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