web

package
v0.0.0-...-1747e0c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package web contains a handful of very useful functions for parsing types from request queries and payloads.

Index

Constants

This section is empty.

Variables

View Source
var (
	JSONContentType = "application/json; charset=UTF-8"
	DateISOFormat   = "2006-01-02"
)

Let's have generic errors for expected conditions. Typically these would be http.StatusBadRequest (400)

Functions

func GetInt64Var

func GetInt64Var(r *http.Request, key string) int64

GetInt64Var is a helper to pull gorilla mux Vars. If the value is empty, it falls back to the URL query string. We are ignoring the error here bc we're assuming the path had a [0-9]+ descriptor on this var.

func GetUInt64Var

func GetUInt64Var(r *http.Request, key string) uint64

GetUInt64Var is a helper to pull gorilla mux Vars. If the value is empty, it falls back to the URL query string. We are ignoring the error here bc we're assuming the path had a [0-9]+ descriptor on this var.

func ParseDateRange

func ParseDateRange(vars map[string]string) (startDate time.Time, endDate time.Time, err error)

ParseDateRange will look for and parse 'startDate' and 'endDate' ISO date strings in the given vars map.

func ParseDateRangeFullDay

func ParseDateRangeFullDay(vars map[string]string) (startDate time.Time, endDate time.Time, err error)

ParseDateRangeFullDay will look for and parse 'startDate' and 'endDate' ISO date strings in the given vars map. It will then set the startDate time to midnight and the endDate time to 23:59:59.

func ParseISODate

func ParseISODate(dateStr string) (date time.Time, err error)

ParseISODate is a handy function to accept

func ParseTruthyFalsy

func ParseTruthyFalsy(flag interface{}) (result bool, err error)

ParseTruthyFalsy is a helper method to attempt to parse booleans in APIs that have no set contract on what a boolean should look like.

Types

This section is empty.

Jump to

Keyboard shortcuts

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