Browse code

api/server/httputils: compile with go < 1.7

Signed-off-by: Antonio Murdaca <runcom@redhat.com>

Antonio Murdaca authored on 2016/10/04 19:00:48
Showing 3 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package httputils
2 2
 
3 3
 import (
4
-	"encoding/json"
5 4
 	"fmt"
6 5
 	"io"
7 6
 	"net/http"
... ...
@@ -77,15 +76,6 @@ func ParseForm(r *http.Request) error {
77 77
 	return nil
78 78
 }
79 79
 
80
-// WriteJSON writes the value v to the http response stream as json with standard json encoding.
81
-func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
82
-	w.Header().Set("Content-Type", "application/json")
83
-	w.WriteHeader(code)
84
-	enc := json.NewEncoder(w)
85
-	enc.SetEscapeHTML(false)
86
-	return enc.Encode(v)
87
-}
88
-
89 80
 // VersionFromContext returns an API version from the context using APIVersionKey.
90 81
 // It panics if the context value does not have version.Version type.
91 82
 func VersionFromContext(ctx context.Context) (ver string) {
92 83
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+// +build go1.7
1
+
2
+package httputils
3
+
4
+import (
5
+	"encoding/json"
6
+	"net/http"
7
+)
8
+
9
+// WriteJSON writes the value v to the http response stream as json with standard json encoding.
10
+func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
11
+	w.Header().Set("Content-Type", "application/json")
12
+	w.WriteHeader(code)
13
+	enc := json.NewEncoder(w)
14
+	enc.SetEscapeHTML(false)
15
+	return enc.Encode(v)
16
+}
0 17
new file mode 100644
... ...
@@ -0,0 +1,16 @@
0
+// +build go1.6,!go1.7
1
+
2
+package httputils
3
+
4
+import (
5
+	"encoding/json"
6
+	"net/http"
7
+)
8
+
9
+// WriteJSON writes the value v to the http response stream as json with standard json encoding.
10
+func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
11
+	w.Header().Set("Content-Type", "application/json")
12
+	w.WriteHeader(code)
13
+	enc := json.NewEncoder(w)
14
+	return enc.Encode(v)
15
+}