MCPcopy
hub / github.com/labstack/echo / valuesFromCookie

Function valuesFromCookie

middleware/extractor.go:205–232  ·  view source on GitHub ↗

valuesFromCookie returns a function that extracts values from the named cookie.

(name string, limit uint)

Source from the content-addressed store, hash-verified

203
204// valuesFromCookie returns a function that extracts values from the named cookie.
205func 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.
235func valuesFromForm(name string, limit uint) ValuesExtractor {

Callers 2

createExtractorsFunction · 0.85
TestValuesFromCookieFunction · 0.85

Calls 1

CookiesMethod · 0.80

Tested by 1

TestValuesFromCookieFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…