Skip to content

Commit 094f9a9

Browse files
dmarkhamthinkerou
authored andcommitted
v1.4.0 + gin-gonic#1631 (remove go1.6/go1,7 support) (gin-gonic#1851)
* 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
1 parent 202f8fc commit 094f9a9

21 files changed

+225
-191
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ language: go
33
matrix:
44
fast_finish: true
55
include:
6-
- go: 1.6.x
7-
- go: 1.7.x
86
- go: 1.8.x
97
- go: 1.9.x
108
- go: 1.10.x

CHANGELOG.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,60 @@
1-
# CHANGELOG
1+
2+
### Gin 1.4.0
3+
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+
258

359
### Gin 1.3.0
460

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Gin is a web framework written in Go (Golang). It features a martini-like API wi
6969

7070
To install Gin package, you need to install Go and set your Go workspace first.
7171

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.
7373

7474
```sh
7575
$ go get -u github.com/gin-gonic/gin

context.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ func (c *Context) GetPostFormArray(key string) ([]string, bool) {
439439
if values := req.PostForm[key]; len(values) > 0 {
440440
return values, true
441441
}
442-
if req.MultipartForm != nil && req.MultipartForm.File != nil {
443-
if values := req.MultipartForm.Value[key]; len(values) > 0 {
444-
return values, true
445-
}
446-
}
447442
return []string{}, false
448443
}
449444

@@ -462,13 +457,7 @@ func (c *Context) GetPostFormMap(key string) (map[string]string, bool) {
462457
debugPrint("error on parse multipart form map: %v", err)
463458
}
464459
}
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, exist
460+
return c.get(req.PostForm, key)
472461
}
473462

474463
// get is an internal method and returns a map which satisfy conditions.
@@ -828,6 +817,12 @@ func (c *Context) AsciiJSON(code int, obj interface{}) {
828817
c.Render(code, render.AsciiJSON{Data: obj})
829818
}
830819

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+
831826
// XML serializes the given struct as XML into the response body.
832827
// It also sets the Content-Type as "application/xml".
833828
func (c *Context) XML(code int, obj interface{}) {

context_17.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

context_17_test.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

context_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ func TestContextGetCookie(t *testing.T) {
622622
}
623623

624624
func TestContextBodyAllowedForStatus(t *testing.T) {
625-
// todo(thinkerou): go1.6 not support StatusProcessing
626-
assert.False(t, false, bodyAllowedForStatus(102))
625+
assert.False(t, false, bodyAllowedForStatus(http.StatusProcessing))
627626
assert.False(t, false, bodyAllowedForStatus(http.StatusNoContent))
628627
assert.False(t, false, bodyAllowedForStatus(http.StatusNotModified))
629628
assert.True(t, true, bodyAllowedForStatus(http.StatusInternalServerError))
@@ -794,6 +793,18 @@ func TestContextRenderNoContentAsciiJSON(t *testing.T) {
794793
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
795794
}
796795

796+
// Tests that the response is serialized as JSON
797+
// and Content-Type is set to application/json
798+
// and special HTML characters are preserved
799+
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+
797808
// Tests that the response executes the templates
798809
// and responds with Content-Type set to text/html
799810
func TestContextRenderHTML(t *testing.T) {
@@ -1092,9 +1103,7 @@ func TestContextRenderRedirectAll(t *testing.T) {
10921103
assert.Panics(t, func() { c.Redirect(299, "/resource") })
10931104
assert.Panics(t, func() { c.Redirect(309, "/resource") })
10941105
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.StatusPermanentRedirect
1097-
assert.NotPanics(t, func() { c.Redirect(308, "/resource") })
1106+
assert.NotPanics(t, func() { c.Redirect(http.StatusPermanentRedirect, "/resource") })
10981107
}
10991108

11001109
func TestContextNegotiationWithJSON(t *testing.T) {

debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515
)
1616

17-
const ginSupportMinGoVer = 6
17+
const ginSupportMinGoVer = 8
1818

1919
// IsDebugging returns true if the framework is running in debug mode.
2020
// Use SetMode(gin.ReleaseMode) to disable debug mode.
@@ -69,7 +69,7 @@ func getMinVer(v string) (uint64, error) {
6969

7070
func debugPrintWARNINGDefault() {
7171
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.
7373
7474
`)
7575
}

debug_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestDebugPrintWARNINGDefault(t *testing.T) {
9191
})
9292
m, e := getMinVer(runtime.Version())
9393
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)
9595
} else {
9696
assert.Equal(t, "[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
9797
}

gin_integration_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"crypto/tls"
1010
"fmt"
11+
"html/template"
1112
"io/ioutil"
1213
"net"
1314
"net/http"
@@ -69,6 +70,42 @@ func TestRunTLS(t *testing.T) {
6970
testRequest(t, "https://localhost:8443/example")
7071
}
7172

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 server
102+
// otherwise the main thread will complete
103+
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+
72109
func TestRunEmptyWithEnv(t *testing.T) {
73110
os.Setenv("PORT", "3123")
74111
router := New()

recovery_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a MIT style
33
// license that can be found in the LICENSE file.
44

5-
// +build go1.7
6-
75
package gin
86

97
import (

render/json.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ type AsciiJSON struct {
4343
// SecureJSONPrefix is a string which represents SecureJSON prefix.
4444
type SecureJSONPrefix string
4545

46+
// PureJSON contains the given interface object.
47+
type PureJSON struct {
48+
Data interface{}
49+
}
50+
4651
var jsonContentType = []string{"application/json; charset=utf-8"}
4752
var jsonpContentType = []string{"application/javascript; charset=utf-8"}
4853
var jsonAsciiContentType = []string{"application/json"}
@@ -174,3 +179,16 @@ func (r AsciiJSON) Render(w http.ResponseWriter) (err error) {
174179
func (r AsciiJSON) WriteContentType(w http.ResponseWriter) {
175180
writeContentType(w, jsonAsciiContentType)
176181
}
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+
}

render/json_17.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

render/redirect.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ type Redirect struct {
1818

1919
// Render (Redirect) redirects the http request to new location and writes redirect response.
2020
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.StatusPermanentRedirect
23-
if (r.Code < 300 || r.Code > 308) && r.Code != 201 {
21+
if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated {
2422
panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
2523
}
2624
http.Redirect(w, r.Request, r.Location, r.Code)

render/render_17_test.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)