MCPcopy Index your code
hub / github.com/zalando/skipper / serveTableWalk

Function serveTableWalk

script/script.go:351–398  ·  view source on GitHub ↗
(res *http.Response)

Source from the content-addressed store, hash-verified

349}
350
351func serveTableWalk(res *http.Response) func(lua.LValue, lua.LValue) {
352 return func(k, v lua.LValue) {
353 sk, ok := k.(lua.LString)
354 if !ok {
355 // TODO(sszuecs): https://github.com/zalando/skipper/issues/1487
356 // s.RaiseError("unsupported key type %v, need a string", k.Type())
357 return
358 }
359 switch string(sk) {
360 case "status_code":
361 n, ok := v.(lua.LNumber)
362 if !ok {
363 // TODO(sszuecs): https://github.com/zalando/skipper/issues/1487
364 // s.RaiseError("unsupported status_code type %v, need a number", v.Type())
365 return
366 }
367 res.StatusCode = int(n)
368
369 case "header":
370 t, ok := v.(*lua.LTable)
371 if !ok {
372 // TODO(sszuecs): https://github.com/zalando/skipper/issues/1487
373 // s.RaiseError("unsupported header type %v, need a table", v.Type())
374 return
375 }
376 h := make(http.Header)
377 t.ForEach(serveHeaderWalk(h))
378 res.Header = h
379
380 case "body":
381 var body []byte
382 var err error
383 switch v.Type() {
384 case lua.LTString:
385 data := string(v.(lua.LString))
386 body = []byte(data)
387 case lua.LTTable:
388 body, err = gjson.Encode(v.(*lua.LTable))
389 if err != nil {
390 // TODO(sszuecs): https://github.com/zalando/skipper/issues/1487
391 // s.RaiseError("%v", err)
392 return
393 }
394 }
395 res.Body = io.NopCloser(bytes.NewBuffer(body))
396 }
397 }
398}
399
400func serveHeaderWalk(h http.Header) func(lua.LValue, lua.LValue) {
401 return func(k, v lua.LValue) {

Callers 1

serveRequestFunction · 0.85

Calls 1

serveHeaderWalkFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…