-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PureJSON renderer #694
Conversation
Looks like it's not compiling 😆
could someone help me out? The code looks good to me. Edit: error logs from travis were more helpful, will fix |
@megapctr Maybe you should add |
@cristaloleg the problem is that this feature is available in go 1.7 only. I don't know how to handle that for earlier versions. Any tips? |
I'm referring to |
Sorry for being a bit blunt, but the way you could be dealing with the Go 1.7 issue is by first releasing version 1.0 of Gin, it's about time to put a line in the sand and doing a 1.0 release (Gin to me seems a bit "stuck" to me as 1.0 never comes out). Then any Gin releases after 1.0 making them for Go 1.7 only. Then users of Go 1.6 and below can still use the 1.0 release if they want. |
I see. It's ok for me to wait until gin is ready for the next step. Besides, this PR isn't any crucial feature at all. Sending a json works fine either way. With PureJSON you cut a few bytes off from the response size, which may be helpful in some rare cases |
@megapctr Could you fix the conflicts? |
@megapctr conflicts. |
render/render_test.go
Outdated
t, | ||
w.Body.String(), | ||
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}\n") | ||
assert.Equal(t, w.Header().Get("Content-Type"), "application/json; charset=utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be assert.Equal(t, expect, actual)
@megapctr can you help to add example to |
compile error: |
I have trouble running tests locally so I'll rely on travis |
@thinkerou you mean the main readme? I think it would be identical to the existing example, except it would use What should I do to support go 1.6? |
@megapctr add https://github.com/gin-gonic/gin#jsonp after. Now still support go1.6. |
@appleboy What should I do about go 1.6? |
maybe we should create new file and add build tag in top of file
|
Travis hates me today 😢 Apart from that is everything looking ok? |
context_17.go
Outdated
@@ -0,0 +1,17 @@ | |||
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
// Use of this source code is governed by a MIT style | |||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
context_17_test.go
Outdated
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
render/json_17.go
Outdated
@@ -0,0 +1,28 @@ | |||
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
// Use of this source code is governed by a MIT style | |||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
render/render_17_test.go
Outdated
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
@thinkerou I don't know why |
Oh....@appleboy Makefile not update lead to the error, because the pull request commit to |
context_17_test.go
Outdated
func TestContextRenderPureJSON(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
c, _ := CreateTestContext(w) | ||
c.PureJSON(201, H{"foo": "bar", "html": "<b>"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change 201
to http status code
context_test.go
Outdated
func TestContextRenderJSON(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
c, _ := CreateTestContext(w) | ||
|
||
c.JSON(201, H{"foo": "bar"}) | ||
c.JSON(201, H{"foo": "bar", "html": "<b>"}) | ||
|
||
assert.Equal(t, 201, w.Code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change 201
to http status code
render/json_17.go
Outdated
@@ -0,0 +1,28 @@ | |||
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
// Use of this source code is governed by a MIT style | |||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change to
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
render/render_17_test.go
Outdated
@@ -0,0 +1,26 @@ | |||
// Copyright 2014 Manu Martinez-Almeida. All rights reserved. | |||
// Use of this source code is governed by a MIT style | |||
// license that can be found in the LICENSE file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change to
// Copyright 2018 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
context_17_test.go
Outdated
c, _ := CreateTestContext(w) | ||
c.PureJSON(201, H{"foo": "bar", "html": "<b>"}) | ||
assert.Equal(t, 201, w.Code) | ||
assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too
context_test.go
Outdated
assert.Equal( | ||
t, | ||
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}", | ||
w.Body.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to use one line
render/render_test.go
Outdated
assert.Equal( | ||
t, | ||
"{\"foo\":\"bar\",\"html\":\"\\u003cb\\u003e\"}\n", | ||
w.Body.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to use one line
@megapctr thanks a lot, firstly, can you fix some code according to my review result, secondly, please recommit the pull request to master branch, because it will error which pointed above. thanks again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi, specifically for context.PureJSON - in latest gin version dont see this as option...did I miss something or this never got into release from master? How to render json without escaping? |
The latest release is on 14 Aug 2018.
The feature is merged on 20 Aug 2018
So you don't see the |
Closes #693