MCPcopy Create free account
hub / github.com/docker/cli / tryRawInspectFallback

Method tryRawInspectFallback

cli/command/inspect/inspector.go:126–145  ·  view source on GitHub ↗

tryRawInspectFallback executes the inspect template with a raw interface. This allows docker cli to parse inspect structs injected with Swarm fields.

(rawElement []byte)

Source from the content-addressed store, hash-verified

124// tryRawInspectFallback executes the inspect template with a raw interface.
125// This allows docker cli to parse inspect structs injected with Swarm fields.
126func (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.
148func (i *TemplateInspector) Flush() error {

Callers 1

InspectMethod · 0.95

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected