httputils

package module
v0.0.0-...-a47bbcf Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: MIT Imports: 15 Imported by: 0

README

httputils

HTTP Utils for Golang for creating web apps.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessMiddlewareFactory

func AccessMiddlewareFactory(secret string) func(http.Handler) http.Handler

func ApplySkipLimit

func ApplySkipLimit(query *mdb.Query, skip *int, limit *int) *mdb.Query

func BoolParameterFromRequest

func BoolParameterFromRequest(r *http.Request, name string) *bool

func ConvertMapToValue

func ConvertMapToValue(value interface{}, jsonMap map[string]interface{}) error

func DefaultMiddlewaresFactory

func DefaultMiddlewaresFactory(secret string) func(http.Handler) http.Handler

func Find

func Find(collection *mdb.Collection, q bson.M, skip *int, limit *int) (*interface{}, int)

func FloatParameterFromRequest

func FloatParameterFromRequest(r *http.Request, name string) *float64

func GetBody

func GetBody(req *http.Request) (map[string]interface{}, error)

func GetObjectIdFromURLInRequest

func GetObjectIdFromURLInRequest(r *http.Request, key string) *bson.ObjectId

func GetValidatedBody

func GetValidatedBody(req *http.Request, validatorMap VMap) (map[string]interface{}, error)

func GetValidatedURLParameters

func GetValidatedURLParameters(req *http.Request, validatorMap VMap) (map[string]interface{}, error)

func GetValueFromURLInRequest

func GetValueFromURLInRequest(r *http.Request, key string) *string

func IntParameterFromRequest

func IntParameterFromRequest(r *http.Request, name string) *int

func JSON

func JSON(w http.ResponseWriter, value interface{}, code int)

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

func MapKeys

func MapKeys(m VMap) []string

func Now

func Now() int64

func RandStringBytes

func RandStringBytes(n int) string

func RecoverMiddleware

func RecoverMiddleware(next http.Handler) http.Handler

func SetInContext

func SetInContext(value interface{}, key interface{}, req *http.Request) *http.Request

func UnwrapOrDefaultBool

func UnwrapOrDefaultBool(value *bool, d bool) bool

func UnwrapOrDefaultInt

func UnwrapOrDefaultInt(value *int, d int) int

func UnwrapOrDefaultString

func UnwrapOrDefaultString(value *string, d string) string

func ValidateBody

func ValidateBody(body map[string]interface{}, validatorMap VMap) (map[string]interface{}, error)

func WriteResponseOrError

func WriteResponseOrError(w http.ResponseWriter, code int, response interface{}, err error)

Types

type Error

type Error struct {
	Key         string   `json:"key"`
	Description string   `json:"description"`
	Code        string   `json:"code"`
	Args        []string `json:"args, omitempty"`
}

func UndefinedKeyError

func UndefinedKeyError(code string, description string) Error

func ValidateMap

func ValidateMap(dictionary map[string]interface{}, validatorMap VMap) []Error

func ValidateValue

func ValidateValue(value interface{}, validators []Validator) []Error

func (Error) AsServerError

func (self Error) AsServerError(code int) error

func (Error) Error

func (self Error) Error() string

func (Error) WriteWithCode

func (self Error) WriteWithCode(code int, w http.ResponseWriter)

type Errors

type Errors struct {
	Errors []Error `json:"errors"`
}

func (Errors) Error

func (self Errors) Error() string

type FloatRange

type FloatRange struct {
	Upper  *float64
	Bottom *float64
}

type Int64Range

type Int64Range struct {
	Upper  *int64
	Bottom *int64
}

type IntRange

type IntRange struct {
	Upper  *int
	Bottom *int
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Delete

func (self *Router) Delete(path string, handler http.Handler)

func (*Router) Get

func (self *Router) Get(path string, handler http.Handler)

func (*Router) Post

func (self *Router) Post(path string, handler http.Handler)

func (*Router) Put

func (self *Router) Put(path string, handler http.Handler)

func (*Router) ServeHTTP

func (self *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

type ServerError

type ServerError struct {
	StatusCode int
	Errors     Errors
}

func HTTP400

func HTTP400() ServerError

func HTTP401

func HTTP401() ServerError

func HTTP403

func HTTP403() ServerError

func HTTP404

func HTTP404(id string) ServerError

func (ServerError) Error

func (self ServerError) Error() string

func (ServerError) Write

func (self ServerError) Write(w http.ResponseWriter)

type VMap

type VMap map[string][]Validator

type Validator

type Validator func(value interface{}) error

func ArrayValidator

func ArrayValidator(key string) Validator

func BoolValidator

func BoolValidator(key string) Validator

func CountryValidator

func CountryValidator(key string) Validator

func DateTimeValidator

func DateTimeValidator(key string, t *time.Time) Validator

func FloatInRangeValidator

func FloatInRangeValidator(key string, floatRange FloatRange) Validator

func FloatValidator

func FloatValidator(key string) Validator

func Int64InRangeValidator

func Int64InRangeValidator(key string, intRange Int64Range) Validator

func IntInRangeValidator

func IntInRangeValidator(key string, intRange IntRange) Validator

func IntValidator

func IntValidator(key string) Validator

func LanguageValidator

func LanguageValidator(key string) Validator

func NotEmptyValidator

func NotEmptyValidator(key string) Validator

func ObjectIDValidator

func ObjectIDValidator(key string) Validator

func RequiredBoolValidators

func RequiredBoolValidators(key string, validators ...Validator) []Validator

func RequiredFloatValidators

func RequiredFloatValidators(key string, validators ...Validator) []Validator

func RequiredIntValidators

func RequiredIntValidators(key string, validators ...Validator) []Validator

func RequiredStringValidators

func RequiredStringValidators(key string, validators ...Validator) []Validator

func SexValidator

func SexValidator(key string) Validator

func StringArrayValidator

func StringArrayValidator(key string, each []Validator) Validator

func StringContainsValidator

func StringContainsValidator(key string, values []string) Validator

func StringLengthValidator

func StringLengthValidator(length int, key string) Validator

func StringValidator

func StringValidator(key string) Validator

func TimezoneValidator

func TimezoneValidator(key string) Validator

func URLValidator

func URLValidator(key string) Validator

Jump to

Keyboard shortcuts

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