Documentation ¶
Overview ¶
Package value provides lazy.Value for web context.
Index ¶
- func NewQueryIntInList(key string, values []int, or int) lazy.Value
- func NewQueryIntInRange(key string, min int, max int, or int) lazy.Value
- func NewQueryIntOr(key string, or int) lazy.Value
- func NewQueryStringInList(key string, values []string, or string) lazy.Value
- func NewQueryStringOr(key string, or string) lazy.Value
- func NewRequestValue(f func(*web.Request) (interface{}, error)) lazy.Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewQueryIntInList ¶
NewQueryIntInList is like NewQueryIntOr but it also limits the possible values in the `list“
func NewQueryIntInRange ¶
NewQueryIntInRange is like NewQueryIntOr but it also limits the min and max for the value
func NewQueryIntOr ¶
NewQueryIntOr returns a new *lazy.Value to get the query value by `key` or `or` value if the value is empty or invalid.
Example ¶
val := NewQueryIntOr("foo", 10) r := web.NewRouter(nil) r.Get("/", web.HandlerFunc(func(req *web.Request, next web.NextHandler) *response.Response { v, _ := val.Eval(req.Context()) return response.NewText(v) })) recorder := httptest.NewRecorder(r) fmt.Println( recorder.TestGet("/?foo=5").Body, recorder.TestGet("/?foo=bar").Body, recorder.TestGet("/").Body, )
Output: 5 10 10
func NewQueryStringInList ¶
NewQueryStringInList is like NewQueryStringOr but it also limits the possible values in the `list“
Example ¶
val := NewQueryStringInList("foo", []string{"bar"}, "default") r := web.NewRouter(nil) r.Get("/", web.HandlerFunc(func(req *web.Request, next web.NextHandler) *response.Response { v, _ := val.Eval(req.Context()) return response.NewText(v) })) recorder := httptest.NewRecorder(r) fmt.Println( recorder.TestGet("/?foo=aaa").Body, recorder.TestGet("/?foo=bar").Body, )
Output: default bar
func NewQueryStringOr ¶
NewQueryStringOr returns a new *lazy.Value to get the query value by `key` or `or` value if the value is empty.
Example ¶
val := NewQueryStringOr("foo", "bar") r := web.NewRouter(nil) r.Get("/", web.HandlerFunc(func(req *web.Request, next web.NextHandler) *response.Response { v, _ := val.Eval(req.Context()) return response.NewText(v) })) recorder := httptest.NewRecorder(r) fmt.Println( recorder.TestGet("/?foo=aaa").Body, recorder.TestGet("/").Body, )
Output: aaa bar
func NewRequestValue ¶
NewRequestValue returns a lazy.Value in a request context
Example ¶
val := NewRequestValue(func(req *web.Request) (interface{}, error) { return req.URL.Query().Encode(), nil }) r := web.NewRouter(nil) r.Get("/", web.HandlerFunc(func(req *web.Request, next web.NextHandler) *response.Response { v, _ := val.Eval(req.Context()) return response.NewText(v) })) recorder := httptest.NewRecorder(r) fmt.Println(recorder.TestGet("/?foo=bar").Body)
Output: foo=bar
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.