widget

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 13 Imported by: 10

Documentation

Overview

This file contains a few routines for parsing form values

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPrefixedValues

func AddPrefixedValues(addedTo url.Values, toBeAdded url.Values, prefix string)

func AddValues

func AddValues(addedTo url.Values, toBeAdded url.Values)

func DateRangeToCGIArgs

func DateRangeToCGIArgs(s, e time.Time) string

func DateRangeToValues

func DateRangeToValues(s, e time.Time) url.Values

func ExtractAllCGIArgs

func ExtractAllCGIArgs(r *http.Request) url.Values

ExtractAllCGIArgs gets both GET and POST arguments into a single map

func FormValueCheckbox

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

func FormValueCommaSepStrings

func FormValueCommaSepStrings(r *http.Request, name string) []string

func FormValueCommaSpaceSepStrings

func FormValueCommaSpaceSepStrings(r *http.Request, name string) []string

Separate by comma, or space

func FormValueDateRange

func FormValueDateRange(r *http.Request) (s, e time.Time, err error)

Return values:

s  will be the first second of the first day;
e  will be the last second of the last day;

For ranges of exactly one day, e and s will be in the same day.

Formats:

?date=today
?date=yesterday
?date=day&day=2006/01/02
?date=range&range_from=2006/01/01&range_to=2018/01/01

func FormValueDuration

func FormValueDuration(r *http.Request, name string) time.Duration

As well as the normal syntax, we support "7d", where a day is 24*time.Hour.

func FormValueEpochTime

func FormValueEpochTime(r *http.Request, name string) time.Time

func FormValueFloat64

func FormValueFloat64(w http.ResponseWriter, r *http.Request, name string) float64

func FormValueFloat64EatErrs

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

func FormValueFloat64WithDefault

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

func FormValueInt64

func FormValueInt64(r *http.Request, name string) int64

func FormValueIntWithDefault

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

func GetTemplates

func GetTemplates(ctx context.Context) *template.Template

GetFoo: given a context, extracts the object (or panics; should not be optional)

func ParseRecursive

func ParseRecursive(t *template.Template, dir string) *template.Template

ParseRecursive walks the directory structure, loading all the files it finds. Will panic on failure. Follows symlinks.

func URLStringReplacingGETArgs

func URLStringReplacingGETArgs(r *http.Request, vals *url.Values) string

Creates a URL that matches the request, adding the vals as CGI GET parameters

func ValuesIntoTemplateParams

func ValuesIntoTemplateParams(stem string, values url.Values, params map[string]interface{})

ValuesIntoTemplateParams converts a set of url.Values into template parameters, suitable

for initializing HTML form elements

Types

type BaseHandler

type BaseHandler func(http.ResponseWriter, *http.Request)

func WithCtx

func WithCtx(f CtxMaker, ch ContextHandler) BaseHandler

Outermost wrapper; all other wrappers take (and return) contexthandlers

type ContextHandler

type ContextHandler func(context.Context, http.ResponseWriter, *http.Request)

func WithTemplates

func WithTemplates(t *template.Template, ch ContextHandler) ContextHandler

WithFoo: injects relevant object into the context

type CtxMaker

type CtxMaker func(*http.Request) context.Context

type Presenter

type Presenter interface {
	Values() url.Values
	FromFormValues(v url.Values, stem string) error
}

Jump to

Keyboard shortcuts

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