Skip to content
Myr

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

21 files+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.45// +build go1.767package render89import (10 "net/http"1112 "github.com/gin-gonic/gin/internal/json"13)1415// PureJSON contains the given interface object.16type PureJSON struct {17 Data interface{}18}1920// Render (PureJSON) writes custom ContentType and encodes the given interface object.21func (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}2728// WriteContentType (PureJSON) writes custom ContentType.29func (r PureJSON) WriteContentType(w http.ResponseWriter) {30 writeContentType(w, jsonContentType)31}
modified:render/json.go+18 added
41 unmodified lines
4243// SecureJSONPrefix is a string which represents SecureJSON prefix.44type SecureJSONPrefix string4546// PureJSON contains the given interface object.47type PureJSON struct {48 Data interface{}49}5051var jsonContentType = []string{"application/json; charset=utf-8"}52var jsonpContentType = []string{"application/javascript; charset=utf-8"}53var jsonAsciiContentType = []string{"application/json"}54
123 unmodified lines
178// WriteContentType (AsciiJSON) writes JSON ContentType.179func (r AsciiJSON) WriteContentType(w http.ResponseWriter) {180 writeContentType(w, jsonAsciiContentType)181}182183// Render (PureJSON) writes custom ContentType and encodes the given interface object.184func (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}190191// WriteContentType (PureJSON) writes custom ContentType.192func (r PureJSON) WriteContentType(w http.ResponseWriter) {193 writeContentType(w, jsonContentType)194}
modified:render/redirect.go+1 added-3 removed
16 unmodified lines
17}1819// Render (Redirect) redirects the http request to new location and writes redirect response.20func (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 nil
4 unmodified lines
deleted: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.45// +build go1.767package render89import (10 "net/http/httptest"11 "testing"1213 "github.com/stretchr/testify/assert"14)1516func 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 lines
214 // json: unsupported type: chan int215 assert.Error(t, (AsciiJSON{data}).Render(w))216}217218func 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}229230type xmlmap map[string]interface{}231232// Allows type H to be used with xml.Marshal233func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
267 unmodified lines
modified:vendor/vendor.json+62 added-22 removed
modified:.travis.yml-2 removed
modified:CHANGELOG.md+57 added-1 removed
1# CHANGELOG12### Gin 1.4.034- [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)575859### Gin 1.3.06061- [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 lines
deleted: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.45// +build go1.767package gin89import (10 "net/http"11 "net/http/httptest"12 "testing"1314 "github.com/stretchr/testify/assert"15)1617// Tests that the response is serialized as JSON18// and Content-Type is set to application/json19// and special HTML characters are preserved20func 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.45// +build go1.767package gin89import (10 "github.com/gin-gonic/gin/render"11)1213// 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.15func (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 lines
621 assert.Error(t, err)622}623624func 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 lines
792 assert.Empty(t, w.Body.String())793 assert.Equal(t, "application/json", w.Header().Get("Content-Type"))794}795796// Tests that the response is serialized as JSON797// and Content-Type is set to application/json798// and special HTML characters are preserved799func 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}807808// Tests that the response executes the templates809// and responds with Content-Type set to text/html810func TestContextRenderHTML(t *testing.T) {811 w := httptest.NewRecorder()
290 unmodified lines
1102 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}11081109func TestContextNegotiationWithJSON(t *testing.T) {1110 w := httptest.NewRecorder()
713 unmodified lines
modified:context.go+7 added-12 removed
437 unmodified lines
438 }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}444445// PostFormMap returns a map for a given form key.
10 unmodified lines
456 if err != http.ErrNotMultipart {457 debugPrint("error on parse multipart form map: %v", err)458 }459 }465 dicts, exist := c.get(req.PostForm, key)466467 if !exist && req.MultipartForm != nil && req.MultipartForm.File != nil {468 dicts, exist = c.get(req.MultipartForm.Value, key)469 }470471 return dicts, exist460 return c.get(req.PostForm, key)461}462463// get is an internal method and returns a map which satisfy conditions.464func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) {
351 unmodified lines
816func (c *Context) AsciiJSON(code int, obj interface{}) {817 c.Render(code, render.AsciiJSON{Data: obj})818}819820// 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.822func (c *Context) PureJSON(code int, obj interface{}) {823 c.Render(code, render.PureJSON{Data: obj})824}825826// XML serializes the given struct as XML into the response body.827// It also sets the Content-Type as "application/xml".828func (c *Context) XML(code int, obj interface{}) {829 c.Render(code, render.XML{Data: obj})
194 unmodified lines
modified:debug_test.go+1 added-1 removed
89 unmodified lines
90 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 lines
modified:debug.go+2 added-2 removed
12 unmodified lines
13 "strconv"14 "strings"15)1617const ginSupportMinGoVer = 617const ginSupportMinGoVer = 81819// IsDebugging returns true if the framework is running in debug mode.20// Use SetMode(gin.ReleaseMode) to disable debug mode.21func IsDebugging() bool {
46 unmodified lines
68}6970func 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.7374`)75 }76 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
27 unmodified lines
modified:gin_integration_test.go+37 added
6 unmodified lines
7import (8 "bufio"9 "crypto/tls"10 "fmt"11 "html/template"12 "io/ioutil"13 "net"14 "net/http"15 "net/http/httptest"
53 unmodified lines
69 assert.Error(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))70 testRequest(t, "https://localhost:8443/example")71}7273func 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`))8586 router := New()87 router.Static("./assets", "./assets")88 router.SetHTMLTemplate(html)8990 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 })9798 assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))99 }()100101 // have to wait for the goroutine to start and run the server102 // otherwise the main thread will complete103 time.Sleep(5 * time.Millisecond)104105 assert.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))106 testRequest(t, "https://localhost:8449/pusher")107}108109func TestRunEmptyWithEnv(t *testing.T) {110 os.Setenv("PORT", "3123")111 router := New()112 go func() {
152 unmodified lines
modified:README.md+1 added-1 removed
67 unmodified lines
68## Installation6970To install Gin package, you need to install Go and set your Go workspace first.71721. Download and install it:721. The first need [Go](https://golang.org/) installed (**version 1.8+ is required**), then you can use the below Go command to install Gin.7374```sh75$ go get -u github.com/gin-gonic/gin76```
1994 unmodified lines
modified: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.45// +build go1.765package gin67import (8 "bytes"
138 unmodified lines
deleted:response_writer_1.7.go-12 removed
1// +build !go1.823// 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.67package gin89// ResponseWriter ...10type ResponseWriter interface {11 responseWriterBase12}
deleted:response_writer_1.8.go-25 removed
1// +build go1.823// 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.67package gin89import (10 "net/http"11)1213// ResponseWriter ...14type ResponseWriter interface {15 responseWriterBase16 // get the http.Pusher for server push17 Pusher() http.Pusher18}1920func (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 lines
15 noWritten = -116 defaultStatus = http.StatusOK17)1819type responseWriterBase interface {19// ResponseWriter ...20type ResponseWriter interface {21 http.ResponseWriter22 http.Hijacker23 http.Flusher24 http.CloseNotifier
12 unmodified lines
37 Written() bool3839 // Forces to write the http header (status code + headers).40 WriteHeaderNow()4142 // get the http.Pusher for server push43 Pusher() http.Pusher44}4546type responseWriter struct {47 http.ResponseWriter
68 unmodified lines
116func (w *responseWriter) Flush() {117 w.WriteHeaderNow()118 w.ResponseWriter.(http.Flusher).Flush()119}120121func (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 lines
45package gin67// Version is the current gin framework's version.8const Version = "v1.4.0-dev"8const Version = "v1.4.0"