httpreq

package
v0.0.0-...-c71ac7b Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package httpreq is a set of helper to extract data from HTTP Request.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongType = errors.New("wrong type for the given convertion function")
)

Common errors.

Functions

func ToBool

func ToBool(src string, dest interface{}) error

ToBool takes the given string, parses it as bool and sets it to `dest`. NOTE: considers empty/invalid value as false

func ToCommaList

func ToCommaList(src string, dest interface{}) error

ToCommaList takes the given string and splits it on `,` then set the resulting slice to `dest`.

func ToFloat64

func ToFloat64(src string, dest interface{}) error

ToFloat64 takes the given string, parses it as float64 and sets it to `dest`.

func ToInt

func ToInt(src string, dest interface{}) error

ToInt takes the given string, parses it as int and sets it to `dest`.

func ToRFC3339Time

func ToRFC3339Time(src string, dest interface{}) error

ToRFC3339Time takes the given string, parses it as timestamp and sets it to `dest`.

func ToString

func ToString(src string, dest interface{}) error

ToString takes the given string and sets it to `dest`.

func ToTSTime

func ToTSTime(src string, dest interface{}) error

ToTSTime takes the given string, parses it as timestamp and sets it to `dest`.

Types

type Getter

type Getter interface {
	// Get key return value.
	Get(string) string
}

Getter is the basic interface to extract the intput data. Commonly used with http.Request.Form.

type ParsingMap

type ParsingMap []ParsingMapElem

ParsingMap is a list of ParsingMapElem.

func NewParsingMap

func NewParsingMap() *ParsingMap

NewParsingMap create a new parsing map and returns a pointer to be able to call Add directly.

func NewParsingMapPre

func NewParsingMapPre(n int) *ParsingMap

NewParsingMapPre create a new preallocated parsing map and returns a pointer to be able to call Add directly.

func (*ParsingMap) Add

func (p *ParsingMap) Add(field string, fct func(string, interface{}) error, dest interface{}) *ParsingMap

Add inserts a new field definition in the ParsingMap.

func (ParsingMap) Parse

func (p ParsingMap) Parse(in Getter) error

Parse walks through the ParsingMap and executes it.

func (*ParsingMap) ToBool

func (p *ParsingMap) ToBool(field string, dest interface{}) *ParsingMap

ToBool is a helper for ToBool.

func (*ParsingMap) ToCommaList

func (p *ParsingMap) ToCommaList(field string, dest interface{}) *ParsingMap

ToCommaList is a helper for ToCommaList.

func (*ParsingMap) ToFloat64

func (p *ParsingMap) ToFloat64(field string, dest interface{}) *ParsingMap

ToFloat64 is a helper for ToFloat64.

func (*ParsingMap) ToInt

func (p *ParsingMap) ToInt(field string, dest interface{}) *ParsingMap

ToInt is a helper for ToInt.

func (*ParsingMap) ToRFC3339Time

func (p *ParsingMap) ToRFC3339Time(field string, dest interface{}) *ParsingMap

ToRFC3339Time is a helper for ToRFC3339Time.

func (*ParsingMap) ToString

func (p *ParsingMap) ToString(field string, dest interface{}) *ParsingMap

ToString is a helper for ToString.

func (*ParsingMap) ToTSTime

func (p *ParsingMap) ToTSTime(field string, dest interface{}) *ParsingMap

ToTSTime is a helper for ToTSTime.

type ParsingMapElem

type ParsingMapElem struct {
	Field string
	Fct   func(string, interface{}) error
	Dest  interface{}
}

ParsingMapElem represent the needed elements to parse a given element. - `Field` to be pulled from the `given Getter() interface` - `Fct` the transform function betweend `Getter(Field)` and `Dest` - `Dest` where to store the result.

Jump to

Keyboard shortcuts

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