Hide common codec methods under helpers

The pending codec -> conversion split changes the signature of
Encode and Decode to be more complicated. Create a stub helper
with the exact semantics of today and do the simple mechanical
refactor here to reduce the cost of that change.
This commit is contained in:
Clayton Coleman
2015-12-09 21:15:02 -05:00
parent 229f40e69f
commit 1e21054134
25 changed files with 103 additions and 81 deletions

View File

@@ -406,7 +406,7 @@ func writeJSON(statusCode int, codec runtime.Codec, object runtime.Object, w htt
func prettyJSON(codec runtime.Codec, object runtime.Object, w http.ResponseWriter) {
formatted := &bytes.Buffer{}
output, err := codec.Encode(object)
output, err := runtime.Encode(codec, object)
if err != nil {
errorJSONFatal(err, codec, w)
}
@@ -431,7 +431,7 @@ func errorJSONFatal(err error, codec runtime.Codec, w http.ResponseWriter) int {
util.HandleError(fmt.Errorf("apiserver was unable to write a JSON response: %v", err))
status := errToAPIStatus(err)
code := int(status.Code)
output, err := codec.Encode(status)
output, err := runtime.Encode(codec, status)
if err != nil {
w.WriteHeader(code)
fmt.Fprintf(w, "%s: %s", status.Reason, status.Message)