withCSVOutput wraps the handler of every default-toolset list_* tool so that, at request time, it checks the csv_output feature flag and converts the JSON text response to CSV when enabled. The tool's schema, name, and scope are unchanged — only the response payload format differs.
(tools []inventory.ServerTool)
| 47 | // text response to CSV when enabled. The tool's schema, name, and scope are |
| 48 | // unchanged — only the response payload format differs. |
| 49 | func withCSVOutput(tools []inventory.ServerTool) []inventory.ServerTool { |
| 50 | for i := range tools { |
| 51 | if !isCSVOutputTool(tools[i]) { |
| 52 | continue |
| 53 | } |
| 54 | tools[i].HandlerFunc = wrapHandlerWithCSVOutput(tools[i].HandlerFunc) |
| 55 | } |
| 56 | return tools |
| 57 | } |
| 58 | |
| 59 | // isCSVOutputTool reports whether the given tool should have its handler |
| 60 | // wrapped to honor the csv_output feature flag. Wrapping happens at slice |