v1.4.0 + #1631 (remove go1.6/go1,7 support) (#1851)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* remove go1.6 support * remove build tag * remove todo * remove go1.6 support: https://github.com/gin-gonic/gin/pull/1383/commits * update readme * remove go1.7 support * fix embedmd error * test * revert it * revert it * remove context_17 * add pusher test * v1.4.0 rc1
authored by Dan Markham · committed by 田欧 · parent 202f8fc · Browse files · 21 files·+225 added−191 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+225 added−191 removed
- other:+225 added−191 removed
Provenance
- Commit
094f9a9- Tree
ee5afc2- Author
Dan Markham <dmarkham@gmail.com>- Committer
田欧 <thinkerou@gmail.com>- Parent
202f8fc
21 files changed+225 added−191 removed
deleted:render/json_17.go-31 removed
1-// Copyright 2018 Gin Core Team. All rights reserved.2-// Use of this source code is governed by a MIT style3-// license that can be found in the LICENSE file.4-5-// +build go1.76-7-package render8-9-import (10- "net/http"11-12- "github.com/gin-gonic/gin/internal/json"13-)14-15-// PureJSON contains the given interface object.16-type PureJSON struct {17- Data interface{}18-}19-20-// Render (PureJSON) writes custom ContentType and encodes the given interface object.21-func (r PureJSON) Render(w http.ResponseWriter) error {22- r.WriteContentType(w)23- encoder := json.NewEncoder(w)24- encoder.SetEscapeHTML(false)25- return encoder.Encode(r.Data)26-}27-28-// WriteContentType (PureJSON) writes custom ContentType.29-func (r PureJSON) WriteContentType(w http.ResponseWriter) {30- writeContentType(w, jsonContentType)31-}modified:render/json.go+18 added
41 unmodified lines42 43 // SecureJSONPrefix is a string which represents SecureJSON prefix.44 type SecureJSONPrefix string45 46+// PureJSON contains the given interface object.47+type PureJSON struct {48+ Data interface{}49+}50+51 var jsonContentType = []string{"application/json; charset=utf-8"}52 var jsonpContentType = []string{"application/javascript; charset=utf-8"}53 var jsonAsciiContentType = []string{"application/json"}54 123 unmodified lines178 // WriteContentType (AsciiJSON) writes JSON ContentType.179 func (r AsciiJSON) WriteContentType(w http.ResponseWriter) {180 writeContentType(w, jsonAsciiContentType)181 }182+183+// Render (PureJSON) writes custom ContentType and encodes the given interface object.184+func (r PureJSON) Render(w http.ResponseWriter) error {185+ r.WriteContentType(w)186+ encoder := json.NewEncoder(w)187+ encoder.SetEscapeHTML(false)188+ return encoder.Encode(r.Data)189+}190+191+// WriteContentType (PureJSON) writes custom ContentType.192+func (r PureJSON) WriteContentType(w http.ResponseWriter) {193+ writeContentType(w, jsonContentType)194+}modified:render/redirect.go+1 added-3 removed
16 unmodified lines17 }18 19 // Render (Redirect) redirects the http request to new location and writes redirect response.20 func (r Redirect) Render(w http.ResponseWriter) error {21- // todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)22- // when we upgrade go version we can use http.StatusPermanentRedirect23- if (r.Code < 300 || r.Code > 308) && r.Code != 201 {21+ if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated {22 panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))23 }24 http.Redirect(w, r.Request, r.Location, r.Code)25 return nil4 unmodified linesdeleted:render/render_17_test.go-26 removed
1-// Copyright 2018 Gin Core Team. All rights reserved.2-// Use of this source code is governed by a MIT style3-// license that can be found in the LICENSE file.4-5-// +build go1.76-7-package render8-9-import (10- "net/http/httptest"11- "testing"12-13- "github.com/stretchr/testify/assert"14-)15-16-func TestRenderPureJSON(t *testing.T) {17- w := httptest.NewRecorder()18- data := map[string]interface{}{19- "foo": "bar",20- "html": "<b>",21- }22- err := (PureJSON{data}).Render(w)23- assert.NoError(t, err)24- assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())25- assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))26-}modified:render/render_test.go+12 added
213 unmodified lines214 // json: unsupported type: chan int215 assert.Error(t, (AsciiJSON{data}).Render(w))216 }217 218+func TestRenderPureJSON(t *testing.T) {219+ w := httptest.NewRecorder()220+ data := map[string]interface{}{221+ "foo": "bar",222+ "html": "<b>",223+ }224+ err := (PureJSON{data}).Render(w)225+ assert.NoError(t, err)226+ assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())227+ assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))228+}229+230 type xmlmap map[string]interface{}231 232 // Allows type H to be used with xml.Marshal233 func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {267 unmodified linesmodified:vendor/vendor.json+62 added-22 removed
12234565 unmodified lines121314151617161718192020212223242522232425262728292 unmodified lines323334353636373839383940414142434445464748495051525354555657585960616263646566676869707172737475767778798081828358848586878889909192939495969798991001016061626310210310410510610714 unmodified lines1221231241258612612788891281291309113113213313495135{ "comment": "v1.3.0", "comment": "v1.4.0", "ignore": "test", "package": [ { "checksumSHA1": "CSPbwbyzqA6sfORicn4HFtIhF/c=",5 unmodified lines }, { "checksumSHA1": "QeKwBtN2df+j+4stw3bQJ6yO4EY=", "path": "github.com/gin-contrib/sse", "revision": "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae", "revisionTime": "2017-01-09T09:34:21Z" "revision": "5545eab6dad3bbbd6c5ae9186383c2a9d23c0dae", "revisionTime": "2019-03-01T06:25:29Z" }, { "checksumSHA1": "mE9XW26JSpe4meBObM6J/Oeq0eg=", "checksumSHA1": "Y2MOwzNZfl4NRNDbLCZa6sgx7O0=", "path": "github.com/golang/protobuf/proto", "revision": "aa810b61a9c79d51363740d207bb46cf8e620ed5", "revisionTime": "2018-08-14T21:14:27Z", "version": "v1.2", "versionExact": "v1.2.0" "revision": "c823c79ea1570fb5ff454033735a8e68575d1d0f", "revisionTime": "2019-02-05T22:20:52Z", "version": "v1.3", "versionExact": "v1.3.0" }, { "checksumSHA1": "WqeEgS7pqqkwK8mlrAZmDgtWJMY=", "path": "github.com/json-iterator/go",2 unmodified lines "version": "v1.1", "versionExact": "v1.1.5" }, { "checksumSHA1": "w5RcOnfv5YDr3j2bd1YydkPiZx4=", "checksumSHA1": "rrXDDvz+nQ2KRLQk6nxWaE5Zj1U=", "path": "github.com/mattn/go-isatty", "revision": "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c", "revisionTime": "2017-11-07T05:05:31Z", "revision": "369ecd8cea9851e459abb67eb171853e3986591e", "revisionTime": "2019-02-25T17:38:24Z", "version": "v0.0", "versionExact": "v0.0.4" "versionExact": "v0.0.6" }, { "checksumSHA1": "ZTcgWKWHsrX0RXYVXn5Xeb8Q0go=", "path": "github.com/modern-go/concurrent", "revision": "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94", "revisionTime": "2018-03-06T01:26:44Z" }, { "checksumSHA1": "qvH48wzTIV3QKSDqI0dLFtVjaDI=", "path": "github.com/modern-go/reflect2", "revision": "94122c33edd36123c84d5368cfb2b69df93a0ec8", "revisionTime": "2018-07-18T01:23:57Z" }, { "checksumSHA1": "LuFv4/jlrmFNnDb/5SCSEPAM9vU=", "path": "github.com/pmezard/go-difflib/difflib", "revision": "5d4384ee4fb2527b0a1256a821ebfc92f91efefc", "revisionTime": "2018-12-26T10:54:42Z" }, { "checksumSHA1": "cpNsoLqBprpKh+VZTBOZNVXzBEk=", "path": "github.com/stretchr/objx", "revision": "c61a9dfcced1815e7d40e214d00d1a8669a9f58c", "revisionTime": "2019-02-11T16:23:28Z" }, { "checksumSHA1": "DBdcVxnvaINHhWyyGgih/Mel6gE=", "path": "github.com/stretchr/testify", "revision": "ffdc059bfe9ce6a4e144ba849dbedead332c6053", "revisionTime": "2018-12-05T02:12:43Z", "version": "v1.3", "versionExact": "v1.3.0" }, { "checksumSHA1": "c6pbpF7eowwO59phRTpF8cQ80Z0=", "path": "github.com/stretchr/testify/assert", "revision": "f35b8ab0b5a2cef36673838d662e249dd9c94686", "revisionTime": "2018-05-06T18:05:49Z", "version": "v1.2", "versionExact": "v1.2.2" }, { "checksumSHA1": "5Bd8RPhhaKcEXkagzPqymP4Gx5E=", "checksumSHA1": "fg3TzS9/QK3wZbzei3Z6O8XPLHg=", "path": "github.com/stretchr/testify/http", "revision": "ffdc059bfe9ce6a4e144ba849dbedead332c6053", "revisionTime": "2018-12-05T02:12:43Z", "version": "v1.3", "versionExact": "v1.3.0" }, { "checksumSHA1": "lsdl3fgOiM4Iuy7xjTQxiBtAwB0=", "path": "github.com/stretchr/testify/mock", "revision": "ffdc059bfe9ce6a4e144ba849dbedead332c6053", "revisionTime": "2018-12-05T02:12:43Z", "version": "v1.3", "versionExact": "v1.3.0" }, { "checksumSHA1": "WIhpR3EKGueRSJsYOZ6PIsfL4SI=", "path": "github.com/ugorji/go/codec", "revision": "b4c50a2b199d93b13dc15e78929cfb23bfdf21ab", "revisionTime": "2018-04-07T10:07:33Z", "version": "v1.1", "versionExact": "v1.1.1" "revision": "e444a5086c436778cf9281a7059a3d58b9e17935", "revisionTime": "2019-02-04T20:13:41Z" }, { "checksumSHA1": "GtamqiJoL7PGHsN454AoffBFMa8=", "path": "golang.org/x/net/context",14 unmodified lines "version": "v8.18.2", "versionExact": "v8.18.2" }, { "checksumSHA1": "ZSWoOPUNRr5+3dhkLK3C4cZAQPk=", "checksumSHA1": "QqDq2x8XOU7IoOR98Cx1eiV5QY8=", "path": "gopkg.in/yaml.v2", "revision": "5420a8b6744d3b0345ab293f6fcba19c978f1183", "revisionTime": "2018-03-28T19:50:20Z", "revision": "51d6538a90f86fe93ac480b35f37b2be17fef232", "revisionTime": "2018-11-15T11:05:04Z", "version": "v2.2", "versionExact": "v2.2.1" "versionExact": "v2.2.2" } ], "rootPath": "github.com/gin-gonic/gin"}}No newline at end of filemodified:.travis.yml-2 removed
1234567678935 unmodified lineslanguage: go
matrix: fast_finish: true include: - go: 1.6.x - go: 1.7.x - go: 1.8.x - go: 1.9.x - go: 1.10.x - go: 1.11.x35 unmodified linesmodified:CHANGELOG.md+57 added-1 removed
1-# CHANGELOG1 2+### Gin 1.4.03+4+- [NEW] Support for [Go Modules](https://github.com/golang/go/wiki/Modules) [#1569](https://github.com/gin-gonic/gin/pull/1569)5+- [NEW] Refactor of form mapping multipart requesta [#1829](https://github.com/gin-gonic/gin/pull/1829)6+- [FIX] Truncate Latency precision in long running request [#1830](https://github.com/gin-gonic/gin/pull/1830)7+- [FIX] IsTerm flag should not be affected by DisableConsoleColor method. [#1802](https://github.com/gin-gonic/gin/pull/1802)8+- [NEW] Supporting file binding [#1264](https://github.com/gin-gonic/gin/pull/1264)9+- [NEW] Add support for mapping arrays [#1797](https://github.com/gin-gonic/gin/pull/1797)10+- [FIX] Readme updates [#1793](https://github.com/gin-gonic/gin/pull/1793) [#1788](https://github.com/gin-gonic/gin/pull/1788) [1789](https://github.com/gin-gonic/gin/pull/1789)11+- [FIX] StaticFS: Fixed Logging two log lines on 404. [#1805](https://github.com/gin-gonic/gin/pull/1805), [#1804](https://github.com/gin-gonic/gin/pull/1804)12+- [NEW] Make context.Keys available as LogFormatterParams [#1779](https://github.com/gin-gonic/gin/pull/1779)13+- [NEW] Use internal/json for Marshal/Unmarshal [#1791](https://github.com/gin-gonic/gin/pull/1791)14+- [NEW] Support mapping time.Duration [#1794](https://github.com/gin-gonic/gin/pull/1794)15+- [NEW] Refactor form mappings [#1749](https://github.com/gin-gonic/gin/pull/1749)16+- [NEW] Added flag to context.Stream indicates if client disconnected in middle of stream [#1252](https://github.com/gin-gonic/gin/pull/1252)17+- [FIX] Moved [examples](https://github.com/gin-gonic/examples) to stand alone Repo [#1775](https://github.com/gin-gonic/gin/pull/1775)18+- [NEW] Extend context.File to allow for the content-dispositon attachments via a new method context.Attachment [#1260](https://github.com/gin-gonic/gin/pull/1260)19+- [FIX] Support HTTP content negotiation wildcards [#1112](https://github.com/gin-gonic/gin/pull/1112)20+- [NEW] Add prefix from X-Forwarded-Prefix in redirectTrailingSlash [#1238](https://github.com/gin-gonic/gin/pull/1238)21+- [FIX] context.Copy() race condition [#1020](https://github.com/gin-gonic/gin/pull/1020)22+- [NEW] Add context.HandlerNames() [#1729](https://github.com/gin-gonic/gin/pull/1729)23+- [FIX] Change color methods to public in the defaultLogger. [#1771](https://github.com/gin-gonic/gin/pull/1771)24+- [FIX] Update writeHeaders method to use http.Header.Set [#1722](https://github.com/gin-gonic/gin/pull/1722)25+- [NEW] Add response size to LogFormatterParams [#1752](https://github.com/gin-gonic/gin/pull/1752)26+- [NEW] Allow ignoring field on form mapping [#1733](https://github.com/gin-gonic/gin/pull/1733)27+- [NEW] Add a function to force color in console output. [#1724](https://github.com/gin-gonic/gin/pull/1724)28+- [FIX] Context.Next() - recheck len of handlers on every iteration. [#1745](https://github.com/gin-gonic/gin/pull/1745)29+- [FIX] Fix all errcheck warnings [#1739](https://github.com/gin-gonic/gin/pull/1739) [#1653](https://github.com/gin-gonic/gin/pull/1653)30+- [NEW] context: inherits context cancellation and deadline from http.Request context for Go>=1.7 [#1690](https://github.com/gin-gonic/gin/pull/1690)31+- [NEW] Binding for URL Params [#1694](https://github.com/gin-gonic/gin/pull/1694)32+- [NEW] Add LoggerWithFormatter method [#1677](https://github.com/gin-gonic/gin/pull/1677)33+- [FIX] CI testing updates [#1671](https://github.com/gin-gonic/gin/pull/1671) [#1670](https://github.com/gin-gonic/gin/pull/1670) [#1682](https://github.com/gin-gonic/gin/pull/1682) [#1669](https://github.com/gin-gonic/gin/pull/1669)34+- [FIX] StaticFS(): Send 404 when path does not exist [#1663](https://github.com/gin-gonic/gin/pull/1663)35+- [FIX] Handle nil body for JSON binding [#1638](https://github.com/gin-gonic/gin/pull/1638)36+- [FIX] Support bind uri param [#1612](https://github.com/gin-gonic/gin/pull/1612)37+- [FIX] recovery: fix issue with syscall import on google app engine [#1640](https://github.com/gin-gonic/gin/pull/1640)38+- [FIX] Make sure the debug log contains line breaks [#1650](https://github.com/gin-gonic/gin/pull/1650)39+- [FIX] Panic stack trace being printed during recovery of broken pipe [#1089](https://github.com/gin-gonic/gin/pull/1089) [#1259](https://github.com/gin-gonic/gin/pull/1259)40+- [NEW] RunFd method to run http.Server through a file descriptor [#1609](https://github.com/gin-gonic/gin/pull/1609)41+- [NEW] Yaml binding support [#1618](https://github.com/gin-gonic/gin/pull/1618)42+- [FIX] Pass MaxMultipartMemory when FormFile is called [#1600](https://github.com/gin-gonic/gin/pull/1600)43+- [FIX] LoadHTML* tests [#1559](https://github.com/gin-gonic/gin/pull/1559)44+- [FIX] Removed use of sync.pool from HandleContext [#1565](https://github.com/gin-gonic/gin/pull/1565)45+- [FIX] Format output log to os.Stderr [#1571](https://github.com/gin-gonic/gin/pull/1571)46+- [FIX] Make logger use a yellow background and a darkgray text for legibility [#1570](https://github.com/gin-gonic/gin/pull/1570)47+- [FIX] Remove sensitive request information from panic log. [#1370](https://github.com/gin-gonic/gin/pull/1370)48+- [FIX] log.Println() does not print timestamp [#829](https://github.com/gin-gonic/gin/pull/829) [#1560](https://github.com/gin-gonic/gin/pull/1560)49+- [NEW] Add PureJSON renderer [#694](https://github.com/gin-gonic/gin/pull/694)50+- [FIX] Add missing copyright and update if/else [#1497](https://github.com/gin-gonic/gin/pull/1497)51+- [FIX] Update msgpack usage [#1498](https://github.com/gin-gonic/gin/pull/1498)52+- [FIX] Use protobuf on render [#1496](https://github.com/gin-gonic/gin/pull/1496)53+- [FIX] Add support for Protobuf format response [#1479](https://github.com/gin-gonic/gin/pull/1479)54+- [NEW] Set default time format in form binding [#1487](https://github.com/gin-gonic/gin/pull/1487)55+- [FIX] Add BindXML and ShouldBindXML [#1485](https://github.com/gin-gonic/gin/pull/1485)56+- [NEW] Upgrade dependency libraries [#1491](https://github.com/gin-gonic/gin/pull/1491)57+58+59 ### Gin 1.3.060 61 - [NEW] Add [`func (*Context) QueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.QueryMap), [`func (*Context) GetQueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetQueryMap), [`func (*Context) PostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.PostFormMap) and [`func (*Context) GetPostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetPostFormMap) to support `type map[string]string` as query string or form parameters, see [#1383](https://github.com/gin-gonic/gin/pull/1383)62 - [NEW] Add [`func (*Context) AsciiJSON`](https://godoc.org/github.com/gin-gonic/gin#Context.AsciiJSON), see [#1358](https://github.com/gin-gonic/gin/pull/1358)207 unmodified linesdeleted:context_17_test.go-27 removed
1-// Copyright 2018 Gin Core Team. All rights reserved.2-// Use of this source code is governed by a MIT style3-// license that can be found in the LICENSE file.4-5-// +build go1.76-7-package gin8-9-import (10- "net/http"11- "net/http/httptest"12- "testing"13-14- "github.com/stretchr/testify/assert"15-)16-17-// Tests that the response is serialized as JSON18-// and Content-Type is set to application/json19-// and special HTML characters are preserved20-func TestContextRenderPureJSON(t *testing.T) {21- w := httptest.NewRecorder()22- c, _ := CreateTestContext(w)23- c.PureJSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})24- assert.Equal(t, http.StatusCreated, w.Code)25- assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())26- assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))27-}deleted:context_17.go-17 removed
1-// Copyright 2018 Gin Core Team. All rights reserved.2-// Use of this source code is governed by a MIT style3-// license that can be found in the LICENSE file.4-5-// +build go1.76-7-package gin8-9-import (10- "github.com/gin-gonic/gin/render"11-)12-13-// PureJSON serializes the given struct as JSON into the response body.14-// PureJSON, unlike JSON, does not replace special html characters with their unicode entities.15-func (c *Context) PureJSON(code int, obj interface{}) {16- c.Render(code, render.PureJSON{Data: obj})17-}modified:context_test.go+14 added-5 removed
620 unmodified lines621 assert.Error(t, err)622 }623 624 func TestContextBodyAllowedForStatus(t *testing.T) {625- // todo(thinkerou): go1.6 not support StatusProcessing626- assert.False(t, false, bodyAllowedForStatus(102))625+ assert.False(t, false, bodyAllowedForStatus(http.StatusProcessing))626 assert.False(t, false, bodyAllowedForStatus(http.StatusNoContent))627 assert.False(t, false, bodyAllowedForStatus(http.StatusNotModified))628 assert.True(t, true, bodyAllowedForStatus(http.StatusInternalServerError))629 }162 unmodified lines792 assert.Empty(t, w.Body.String())793 assert.Equal(t, "application/json", w.Header().Get("Content-Type"))794 }795 796+// Tests that the response is serialized as JSON797+// and Content-Type is set to application/json798+// and special HTML characters are preserved799+func TestContextRenderPureJSON(t *testing.T) {800+ w := httptest.NewRecorder()801+ c, _ := CreateTestContext(w)802+ c.PureJSON(http.StatusCreated, H{"foo": "bar", "html": "<b>"})803+ assert.Equal(t, http.StatusCreated, w.Code)804+ assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())805+ assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))806+}807+808 // Tests that the response executes the templates809 // and responds with Content-Type set to text/html810 func TestContextRenderHTML(t *testing.T) {811 w := httptest.NewRecorder()290 unmodified lines1102 assert.Panics(t, func() { c.Redirect(http.StatusAccepted, "/resource") })1103 assert.Panics(t, func() { c.Redirect(299, "/resource") })1104 assert.Panics(t, func() { c.Redirect(309, "/resource") })1105 assert.NotPanics(t, func() { c.Redirect(http.StatusMultipleChoices, "/resource") })1095- // todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)1096- // when we upgrade go version we can use http.StatusPermanentRedirect1097- assert.NotPanics(t, func() { c.Redirect(308, "/resource") })1106+ assert.NotPanics(t, func() { c.Redirect(http.StatusPermanentRedirect, "/resource") })1107 }1108 1109 func TestContextNegotiationWithJSON(t *testing.T) {1110 w := httptest.NewRecorder()713 unmodified linesmodified:context.go+7 added-12 removed
437 unmodified lines438 }439 if values := req.PostForm[key]; len(values) > 0 {440 return values, true441 }442- if req.MultipartForm != nil && req.MultipartForm.File != nil {443- if values := req.MultipartForm.Value[key]; len(values) > 0 {444- return values, true445- }446- }442 return []string{}, false443 }444 445 // PostFormMap returns a map for a given form key.10 unmodified lines456 if err != http.ErrNotMultipart {457 debugPrint("error on parse multipart form map: %v", err)458 }459 }465- dicts, exist := c.get(req.PostForm, key)466-467- if !exist && req.MultipartForm != nil && req.MultipartForm.File != nil {468- dicts, exist = c.get(req.MultipartForm.Value, key)469- }470-471- return dicts, exist460+ return c.get(req.PostForm, key)461 }462 463 // get is an internal method and returns a map which satisfy conditions.464 func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) {351 unmodified lines816 func (c *Context) AsciiJSON(code int, obj interface{}) {817 c.Render(code, render.AsciiJSON{Data: obj})818 }819 820+// PureJSON serializes the given struct as JSON into the response body.821+// PureJSON, unlike JSON, does not replace special html characters with their unicode entities.822+func (c *Context) PureJSON(code int, obj interface{}) {823+ c.Render(code, render.PureJSON{Data: obj})824+}825+826 // XML serializes the given struct as XML into the response body.827 // It also sets the Content-Type as "application/xml".828 func (c *Context) XML(code int, obj interface{}) {829 c.Render(code, render.XML{Data: obj})194 unmodified linesmodified:debug_test.go+1 added-1 removed
89 unmodified lines90 SetMode(TestMode)91 })92 m, e := getMinVer(runtime.Version())93 if e == nil && m <= ginSupportMinGoVer {94- assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)94+ assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.8 or later and Go 1.9 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)95 } else {96 assert.Equal(t, "[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)97 }98 }55 unmodified linesmodified:debug.go+2 added-2 removed
12 unmodified lines13 "strconv"14 "strings"15 )16 17-const ginSupportMinGoVer = 617+const ginSupportMinGoVer = 818 19 // IsDebugging returns true if the framework is running in debug mode.20 // Use SetMode(gin.ReleaseMode) to disable debug mode.21 func IsDebugging() bool {46 unmodified lines68 }69 70 func debugPrintWARNINGDefault() {71 if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {72- debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.72+ debugPrint(`[WARNING] Now Gin requires Go 1.8 or later and Go 1.9 will be required soon.73 74 `)75 }76 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.27 unmodified linesmodified:gin_integration_test.go+37 added
6 unmodified lines7 import (8 "bufio"9 "crypto/tls"10 "fmt"11+ "html/template"12 "io/ioutil"13 "net"14 "net/http"15 "net/http/httptest"53 unmodified lines69 assert.Error(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))70 testRequest(t, "https://localhost:8443/example")71 }72 73+func TestPusher(t *testing.T) {74+ var html = template.Must(template.New("https").Parse(`75+<html>76+<head>77+ <title>Https Test</title>78+ <script src="/assets/app.js"></script>79+</head>80+<body>81+ <h1 style="color:red;">Welcome, Ginner!</h1>82+</body>83+</html>84+`))85+86+ router := New()87+ router.Static("./assets", "./assets")88+ router.SetHTMLTemplate(html)89+90+ go func() {91+ router.GET("/pusher", func(c *Context) {92+ if pusher := c.Writer.Pusher(); pusher != nil {93+ pusher.Push("/assets/app.js", nil)94+ }95+ c.String(http.StatusOK, "it worked")96+ })97+98+ assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))99+ }()100+101+ // have to wait for the goroutine to start and run the server102+ // otherwise the main thread will complete103+ time.Sleep(5 * time.Millisecond)104+105+ assert.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))106+ testRequest(t, "https://localhost:8449/pusher")107+}108+109 func TestRunEmptyWithEnv(t *testing.T) {110 os.Setenv("PORT", "3123")111 router := New()112 go func() {152 unmodified linesmodified:README.md+1 added-1 removed
67 unmodified lines68 ## Installation69 70 To install Gin package, you need to install Go and set your Go workspace first.71 72-1. Download and install it:72+1. The first need [Go](https://golang.org/) installed (**version 1.8+ is required**), then you can use the below Go command to install Gin.73 74 ```sh75 $ go get -u github.com/gin-gonic/gin76 ```1994 unmodified linesmodified:recovery_test.go-2 removed
1 // Copyright 2014 Manu Martinez-Almeida. All rights reserved.2 // Use of this source code is governed by a MIT style3 // license that can be found in the LICENSE file.4 5-// +build go1.76-5 package gin6 7 import (8 "bytes"138 unmodified linesdeleted:response_writer_1.7.go-12 removed
1-// +build !go1.82-3-// Copyright 2018 Gin Core Team. All rights reserved.4-// Use of this source code is governed by a MIT style5-// license that can be found in the LICENSE file.6-7-package gin8-9-// ResponseWriter ...10-type ResponseWriter interface {11- responseWriterBase12-}deleted:response_writer_1.8.go-25 removed
1-// +build go1.82-3-// Copyright 2018 Gin Core Team. All rights reserved.4-// Use of this source code is governed by a MIT style5-// license that can be found in the LICENSE file.6-7-package gin8-9-import (10- "net/http"11-)12-13-// ResponseWriter ...14-type ResponseWriter interface {15- responseWriterBase16- // get the http.Pusher for server push17- Pusher() http.Pusher18-}19-20-func (w *responseWriter) Pusher() (pusher http.Pusher) {21- if pusher, ok := w.ResponseWriter.(http.Pusher); ok {22- return pusher23- }24- return nil25-}modified:response_writer.go+12 added-1 removed
14 unmodified lines15 noWritten = -116 defaultStatus = http.StatusOK17 )18 19-type responseWriterBase interface {19+// ResponseWriter ...20+type ResponseWriter interface {21 http.ResponseWriter22 http.Hijacker23 http.Flusher24 http.CloseNotifier12 unmodified lines37 Written() bool38 39 // Forces to write the http header (status code + headers).40 WriteHeaderNow()41+42+ // get the http.Pusher for server push43+ Pusher() http.Pusher44 }45 46 type responseWriter struct {47 http.ResponseWriter68 unmodified lines116 func (w *responseWriter) Flush() {117 w.WriteHeaderNow()118 w.ResponseWriter.(http.Flusher).Flush()119 }120+121+func (w *responseWriter) Pusher() (pusher http.Pusher) {122+ if pusher, ok := w.ResponseWriter.(http.Pusher); ok {123+ return pusher124+ }125+ return nil126+}modified:version.go+1 added-1 removed
3 unmodified lines4 5 package gin6 7 // Version is the current gin framework's version.8-const Version = "v1.4.0-dev"8+const Version = "v1.4.0"