Bladeren bron

remove fallback for Go 1.4

Windows is now built using Go 1.6, so we no longer
need to have a fallback for Go 1.4.

This removes the fallback that was introduced in
6df3fc51759a6219e965a30c413cb43ddbc897c9 /
https://github.com/docker/docker/pull/18553

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 9 jaren geleden
bovenliggende
commit
6b46a56865
3 gewijzigde bestanden met toevoegingen van 23 en 70 verwijderingen
  1. 23 1
      api/client/inspect/inspector.go
  2. 0 40
      api/client/inspect/inspector_go14.go
  3. 0 29
      api/client/inspect/inspector_go15.go

+ 23 - 1
api/client/inspect/inspector.go

@@ -93,13 +93,35 @@ func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte)
 		if rawElement == nil {
 			return fmt.Errorf("Template parsing error: %v", err)
 		}
-		return i.tryRawInspectFallback(rawElement, err)
+		return i.tryRawInspectFallback(rawElement)
 	}
 	i.buffer.Write(buffer.Bytes())
 	i.buffer.WriteByte('\n')
 	return nil
 }
 
+// tryRawInspectFallback executes the inspect template with a raw interface.
+// This allows docker cli to parse inspect structs injected with Swarm fields.
+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.
 func (i *TemplateInspector) Flush() error {
 	if i.buffer.Len() == 0 {

+ 0 - 40
api/client/inspect/inspector_go14.go

@@ -1,40 +0,0 @@
-// +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 - 29
api/client/inspect/inspector_go15.go

@@ -1,29 +0,0 @@
-// +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
-}