github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/api/client/inspect/inspector_go15.go (about)

     1  // +build go1.5
     2  
     3  package inspect
     4  
     5  import (
     6  	"bytes"
     7  	"encoding/json"
     8  	"fmt"
     9  )
    10  
    11  func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte, _ error) error {
    12  	var raw interface{}
    13  	buffer := new(bytes.Buffer)
    14  	rdr := bytes.NewReader(rawElement)
    15  	dec := json.NewDecoder(rdr)
    16  
    17  	if rawErr := dec.Decode(&raw); rawErr != nil {
    18  		return fmt.Errorf("unable to read inspect data: %v", rawErr)
    19  	}
    20  
    21  	tmplMissingKey := i.tmpl.Option("missingkey=error")
    22  	if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
    23  		return fmt.Errorf("Template parsing error: %v", rawErr)
    24  	}
    25  
    26  	i.buffer.Write(buffer.Bytes())
    27  	i.buffer.WriteByte('\n')
    28  	return nil
    29  }