Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e18dcb87
Commit
e18dcb87
authored
Nov 25, 2014
by
Brian Grant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format JSON by default. Fixes #2243.
parent
12add3bc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
apiserver.go
pkg/apiserver/apiserver.go
+12
-2
No files found.
pkg/apiserver/apiserver.go
View file @
e18dcb87
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
apiserver
package
apiserver
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -286,9 +287,17 @@ func writeJSON(statusCode int, codec runtime.Codec, object runtime.Object, w htt
...
@@ -286,9 +287,17 @@ func writeJSON(statusCode int, codec runtime.Codec, object runtime.Object, w htt
errorJSON
(
err
,
codec
,
w
)
errorJSON
(
err
,
codec
,
w
)
return
return
}
}
// PR #2243: Pretty-print JSON by default.
formatted
:=
&
bytes
.
Buffer
{}
err
=
json
.
Indent
(
formatted
,
output
,
""
,
" "
)
if
err
!=
nil
{
// Note: If codec is broken, this results in an infinite recursion
errorJSON
(
err
,
codec
,
w
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
statusCode
)
w
.
WriteHeader
(
statusCode
)
w
.
Write
(
output
)
w
.
Write
(
formatted
.
Bytes
()
)
}
}
// errorJSON renders an error to the response.
// errorJSON renders an error to the response.
...
@@ -299,7 +308,8 @@ func errorJSON(err error, codec runtime.Codec, w http.ResponseWriter) {
...
@@ -299,7 +308,8 @@ func errorJSON(err error, codec runtime.Codec, w http.ResponseWriter) {
// writeRawJSON writes a non-API object in JSON.
// writeRawJSON writes a non-API object in JSON.
func
writeRawJSON
(
statusCode
int
,
object
interface
{},
w
http
.
ResponseWriter
)
{
func
writeRawJSON
(
statusCode
int
,
object
interface
{},
w
http
.
ResponseWriter
)
{
output
,
err
:=
json
.
Marshal
(
object
)
// PR #2243: Pretty-print JSON by default.
output
,
err
:=
json
.
MarshalIndent
(
object
,
""
,
" "
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment