tryRawInspectFallback executes the inspect template with a raw interface. This allows docker cli to parse inspect structs injected with Swarm fields.
(rawElement []byte)
| 124 | // tryRawInspectFallback executes the inspect template with a raw interface. |
| 125 | // This allows docker cli to parse inspect structs injected with Swarm fields. |
| 126 | func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { |
| 127 | var raw any |
| 128 | buffer := new(bytes.Buffer) |
| 129 | rdr := bytes.NewReader(rawElement) |
| 130 | dec := json.NewDecoder(rdr) |
| 131 | dec.UseNumber() |
| 132 | |
| 133 | if err := dec.Decode(&raw); err != nil { |
| 134 | return fmt.Errorf("unable to read inspect data: %w", err) |
| 135 | } |
| 136 | |
| 137 | tmplMissingKey := i.tmpl.Option("missingkey=error") |
| 138 | if err := tmplMissingKey.Execute(buffer, raw); err != nil { |
| 139 | return fmt.Errorf("template parsing error: %w", err) |
| 140 | } |
| 141 | |
| 142 | i.buffer.Write(buffer.Bytes()) |
| 143 | i.buffer.WriteByte('\n') |
| 144 | return nil |
| 145 | } |
| 146 | |
| 147 | // Flush writes the result of inspecting all elements into the output stream. |
| 148 | func (i *TemplateInspector) Flush() error { |