mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
api/server/httputils: compile with go < 1.7
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
package httputils
|
package httputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -77,15 +76,6 @@ func ParseForm(r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJSON writes the value v to the http response stream as json with standard json encoding.
|
|
||||||
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(code)
|
|
||||||
enc := json.NewEncoder(w)
|
|
||||||
enc.SetEscapeHTML(false)
|
|
||||||
return enc.Encode(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// VersionFromContext returns an API version from the context using APIVersionKey.
|
// VersionFromContext returns an API version from the context using APIVersionKey.
|
||||||
// It panics if the context value does not have version.Version type.
|
// It panics if the context value does not have version.Version type.
|
||||||
func VersionFromContext(ctx context.Context) (ver string) {
|
func VersionFromContext(ctx context.Context) (ver string) {
|
||||||
|
17
api/server/httputils/httputils_write_json.go
Normal file
17
api/server/httputils/httputils_write_json.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// +build go1.7
|
||||||
|
|
||||||
|
package httputils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WriteJSON writes the value v to the http response stream as json with standard json encoding.
|
||||||
|
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(code)
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
enc.SetEscapeHTML(false)
|
||||||
|
return enc.Encode(v)
|
||||||
|
}
|
16
api/server/httputils/httputils_write_json_go16.go
Normal file
16
api/server/httputils/httputils_write_json_go16.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// +build go1.6,!go1.7
|
||||||
|
|
||||||
|
package httputils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WriteJSON writes the value v to the http response stream as json with standard json encoding.
|
||||||
|
func WriteJSON(w http.ResponseWriter, code int, v interface{}) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(code)
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
return enc.Encode(v)
|
||||||
|
}
|
Reference in New Issue
Block a user