utils

package
v0.0.0-...-59e7d7e Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2016 License: MIT, BSD-2-Clause Imports: 5 Imported by: 2

README

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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

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