valuesFromCookie returns a function that extracts values from the named cookie.
(name string, limit uint)
| 203 | |
| 204 | // valuesFromCookie returns a function that extracts values from the named cookie. |
| 205 | func valuesFromCookie(name string, limit uint) ValuesExtractor { |
| 206 | if limit == 0 { |
| 207 | limit = 1 |
| 208 | } |
| 209 | return func(c *echo.Context) ([]string, ExtractorSource, error) { |
| 210 | cookies := c.Cookies() |
| 211 | if len(cookies) == 0 { |
| 212 | return nil, ExtractorSourceCookie, errCookieExtractorValueMissing |
| 213 | } |
| 214 | |
| 215 | i := uint(0) |
| 216 | result := make([]string, 0) |
| 217 | for _, cookie := range cookies { |
| 218 | if name != cookie.Name { |
| 219 | continue |
| 220 | } |
| 221 | result = append(result, cookie.Value) |
| 222 | i++ |
| 223 | if i >= limit { |
| 224 | break |
| 225 | } |
| 226 | } |
| 227 | if len(result) == 0 { |
| 228 | return nil, ExtractorSourceCookie, errCookieExtractorValueMissing |
| 229 | } |
| 230 | return result, ExtractorSourceCookie, nil |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // valuesFromForm returns a function that extracts values from the form field. |
| 235 | func valuesFromForm(name string, limit uint) ValuesExtractor { |
searching dependent graphs…