mirror of https://github.com/docker/docs.git
Merge pull request #18553 from calavera/remove_specific_go_1_5_calls
Remove call to template.Option when building with 1.4.
This commit is contained in:
commit
d46650b3c7
|
@ -39,33 +39,13 @@ func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte)
|
||||||
if rawElement == nil {
|
if rawElement == nil {
|
||||||
return fmt.Errorf("Template parsing error: %v", err)
|
return fmt.Errorf("Template parsing error: %v", err)
|
||||||
}
|
}
|
||||||
return i.tryRawInspectFallback(rawElement)
|
return i.tryRawInspectFallback(rawElement, err)
|
||||||
}
|
}
|
||||||
i.buffer.Write(buffer.Bytes())
|
i.buffer.Write(buffer.Bytes())
|
||||||
i.buffer.WriteByte('\n')
|
i.buffer.WriteByte('\n')
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error {
|
|
||||||
var raw interface{}
|
|
||||||
buffer := new(bytes.Buffer)
|
|
||||||
rdr := bytes.NewReader(rawElement)
|
|
||||||
dec := json.NewDecoder(rdr)
|
|
||||||
|
|
||||||
if rawErr := dec.Decode(&raw); rawErr != nil {
|
|
||||||
return fmt.Errorf("unable to read inspect data: %v", rawErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
tmplMissingKey := i.tmpl.Option("missingkey=error")
|
|
||||||
if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
|
|
||||||
return fmt.Errorf("Template parsing error: %v", rawErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
i.buffer.Write(buffer.Bytes())
|
|
||||||
i.buffer.WriteByte('\n')
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush write the result of inspecting all elements into the output stream.
|
// Flush write the result of inspecting all elements into the output stream.
|
||||||
func (i *TemplateInspector) Flush() error {
|
func (i *TemplateInspector) Flush() error {
|
||||||
_, err := io.Copy(i.outputStream, i.buffer)
|
_, err := io.Copy(i.outputStream, i.buffer)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
// +build !go1.5
|
||||||
|
|
||||||
|
package inspect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// tryeRawInspectFallback executes the inspect template with a raw interface.
|
||||||
|
// This allows docker cli to parse inspect structs injected with Swarm fields.
|
||||||
|
// Unfortunately, go 1.4 doesn't fail executing invalid templates when the input is an interface.
|
||||||
|
// It doesn't allow to modify this behavior either, sending <no value> messages to the output.
|
||||||
|
// We assume that the template is invalid when there is a <no value>, if the template was valid
|
||||||
|
// we'd get <nil> or "" values. In that case we fail with the original error raised executing the
|
||||||
|
// template with the typed input.
|
||||||
|
func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte, originalErr error) error {
|
||||||
|
var raw interface{}
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
rdr := bytes.NewReader(rawElement)
|
||||||
|
dec := json.NewDecoder(rdr)
|
||||||
|
|
||||||
|
if rawErr := dec.Decode(&raw); rawErr != nil {
|
||||||
|
return fmt.Errorf("unable to read inspect data: %v", rawErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rawErr := i.tmpl.Execute(buffer, raw); rawErr != nil {
|
||||||
|
return fmt.Errorf("Template parsing error: %v", rawErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(buffer.String(), "<no value>") {
|
||||||
|
return fmt.Errorf("Template parsing error: %v", originalErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
i.buffer.Write(buffer.Bytes())
|
||||||
|
i.buffer.WriteByte('\n')
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
// +build go1.5
|
||||||
|
|
||||||
|
package inspect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte, _ error) error {
|
||||||
|
var raw interface{}
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
rdr := bytes.NewReader(rawElement)
|
||||||
|
dec := json.NewDecoder(rdr)
|
||||||
|
|
||||||
|
if rawErr := dec.Decode(&raw); rawErr != nil {
|
||||||
|
return fmt.Errorf("unable to read inspect data: %v", rawErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmplMissingKey := i.tmpl.Option("missingkey=error")
|
||||||
|
if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
|
||||||
|
return fmt.Errorf("Template parsing error: %v", rawErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
i.buffer.Write(buffer.Bytes())
|
||||||
|
i.buffer.WriteByte('\n')
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue