MCPcopy
hub / github.com/zalando/skipper / getContextValue

Function getContextValue

script/script.go:406–460  ·  view source on GitHub ↗
(f filters.FilterContext)

Source from the content-addressed store, hash-verified

404}
405
406func getContextValue(f filters.FilterContext) func(*lua.LState) int {
407 var request, response, state_bag, path_param *lua.LTable
408 var serve *lua.LFunction
409 return func(s *lua.LState) int {
410 key := s.ToString(-1)
411 var ret lua.LValue
412 switch key {
413 case "request":
414 // initialize access to request on first use
415 if request == nil {
416 request = s.CreateTable(0, 0)
417 mt := s.CreateTable(0, 2)
418 mt.RawSetString("__index", s.NewFunction(getRequestValue(f)))
419 mt.RawSetString("__newindex", s.NewFunction(setRequestValue(f)))
420 s.SetMetatable(request, mt)
421 }
422 ret = request
423 case "response":
424 if response == nil {
425 response = s.CreateTable(0, 0)
426 mt := s.CreateTable(0, 2)
427 mt.RawSetString("__index", s.NewFunction(getResponseValue(f)))
428 mt.RawSetString("__newindex", s.NewFunction(setResponseValue(f)))
429 s.SetMetatable(response, mt)
430 }
431 ret = response
432 case "state_bag":
433 if state_bag == nil {
434 state_bag = s.CreateTable(0, 0)
435 mt := s.CreateTable(0, 2)
436 mt.RawSetString("__index", s.NewFunction(getStateBag(f)))
437 mt.RawSetString("__newindex", s.NewFunction(setStateBag(f)))
438 s.SetMetatable(state_bag, mt)
439 }
440 ret = state_bag
441 case "path_param":
442 if path_param == nil {
443 path_param = s.CreateTable(0, 0)
444 mt := s.CreateTable(0, 1)
445 mt.RawSetString("__index", s.NewFunction(getPathParam(f)))
446 s.SetMetatable(path_param, mt)
447 }
448 ret = path_param
449 case "serve":
450 if serve == nil {
451 serve = s.NewFunction(serveRequest(f))
452 }
453 ret = serve
454 default:
455 return 0
456 }
457 s.Push(ret)
458 return 1
459 }
460}
461
462func getRequestValue(f filters.FilterContext) func(*lua.LState) int {
463 var header, cookie, url_query *lua.LTable

Callers 1

Calls 8

getRequestValueFunction · 0.85
setRequestValueFunction · 0.85
getResponseValueFunction · 0.85
setResponseValueFunction · 0.85
getStateBagFunction · 0.85
setStateBagFunction · 0.85
getPathParamFunction · 0.85
serveRequestFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…