MCPcopy Create free account
hub / github.com/containerd/nerdctl / tryRawFormat

Function tryRawFormat

pkg/formatter/common.go:90–111  ·  view source on GitHub ↗
(b *bytes.Buffer, f interface{}, tmpl *template.Template)

Source from the content-addressed store, hash-verified

88}
89
90func tryRawFormat(b *bytes.Buffer, f interface{}, tmpl *template.Template) error {
91 m, err := json.MarshalIndent(f, "", " ")
92 if err != nil {
93 return err
94 }
95
96 var raw interface{}
97 rdr := bytes.NewReader(m)
98 dec := json.NewDecoder(rdr)
99 dec.UseNumber()
100
101 if rawErr := dec.Decode(&raw); rawErr != nil {
102 return fmt.Errorf("unable to read inspect data: %v", rawErr)
103 }
104
105 tmplMissingKey := tmpl.Option("missingkey=error")
106 if rawErr := tmplMissingKey.Execute(b, raw); rawErr != nil {
107 return fmt.Errorf("template parsing error: %v", rawErr)
108 }
109
110 return nil
111}
112
113// ParseTemplate wraps github.com/docker/cli/templates.Parse() to allow `json` as an alias of `{{json .}}`.
114// ParseTemplate can be removed when https://github.com/docker/cli/pull/3355 gets merged and tagged (Docker 22.XX).

Callers 1

FormatSliceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…