util

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2018 License: MIT Imports: 9 Imported by: 5

README

Util

Documentation Go Report Card

A set of frequently used Go utility functions.

# download library
$: go get github.com/faryon93/util

# place on top of your go file
import "github.com/faryon93/util"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType = errors.New("invalid content type")
)

Functions

func GetRemoteAddr

func GetRemoteAddr(r *http.Request) string

GetRemoteAddr returns the remote address of an http request. If an X-Forwarded-For Header is present the headers content is returned. Otherwise the src host of the ip packet is returned.

func Jsonify

func Jsonify(w http.ResponseWriter, v interface{})

Jsonify writes the JSON representation of v to the supplied http.ResposeWriter. If an error occours while marshalling the http response will be an internal server error.

func ParseBody

func ParseBody(r *http.Request, v interface{}) error

ParseBody reads the body of the request and parses it into v.

func RandomString

func RandomString(n int) string

RandomString string returns a random string with the length n. Stolen from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-tring-of-a-fixed-length-in-golang

func WaitSignal

func WaitSignal(sig ...os.Signal)

WaitSignal blocks until one of the given OS signals occoures.

Types

This section is empty.

Jump to

Keyboard shortcuts

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