Skip to content

Commit

Permalink
merging from master (#1)
Browse files Browse the repository at this point in the history
* Revert "Adding ppc64le architecture support on travis-ci (gin-gonic#2538)" (gin-gonic#2602)

* test: fixed the TestUnixSocket test on windows (gin-gonic#2595)

Co-authored-by: thinkerou <thinkerou@gmail.com>

* gin mode unknown: show available mode (gin-gonic#2567)

Co-authored-by: thinkerou <thinkerou@gmail.com>

* fix error gin support min Go version (gin-gonic#2584)

Co-authored-by: thinkerou <thinkerou@gmail.com>

* Fixes to the graceful shutdown example (gin-gonic#2552)

* Change error comparison to use errors.Is() and add a line of whitespace before the if statement on graceful shutdown

* Change from log.Fatalf to log.Printf to ensure the graceful shutdown actually works

Co-authored-by: J. J. Bigorra <josep@prowarehouse.nl>
Co-authored-by: thinkerou <thinkerou@gmail.com>

* basic auth: fix timing oracle (gin-gonic#2609)

Co-authored-by: thinkerou <thinkerou@gmail.com>

* chore: Deleted spaces (gin-gonic#2622)

* Remove the tedious named return value (gin-gonic#2620)

Co-authored-by: thinkerou <thinkerou@gmail.com>

Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Jeff <laojianzi1994@gmail.com>
Co-authored-by: Rubi <14269809+codenoid@users.noreply.github.com>
Co-authored-by: Qt <golang.chen@gmail.com>
Co-authored-by: Josep Jesus Bigorra Algaba <42377845+averageflow@users.noreply.github.com>
Co-authored-by: J. J. Bigorra <josep@prowarehouse.nl>
Co-authored-by: Snawoot <vladislav-ex-github@vm-0.com>
Co-authored-by: Alexander Melentyev <55826637+alexander-melentyev@users.noreply.github.com>
Co-authored-by: Andy Pan <panjf2000@gmail.com>
  • Loading branch information
10 people committed Mar 18, 2021
1 parent fca3f95 commit 5723314
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 73 deletions.
28 changes: 0 additions & 28 deletions .travis.yml
Expand Up @@ -7,45 +7,17 @@ matrix:
env: GO111MODULE=on
- go: 1.13.x
- go: 1.13.x
env:
- TESTTAGS=nomsgpack
- go: 1.14.x
- go: 1.14.x
env:
- TESTTAGS=nomsgpack
- go: 1.15.x
- go: 1.15.x
env:
- TESTTAGS=nomsgpack
- go: master
# Adding ppc64le jobs
- go: 1.11.x
arch: ppc64le
env: GO111MODULE=on
- go: 1.12.x
arch: ppc64le
env: GO111MODULE=on
- go: 1.13.x
arch: ppc64le
- go: 1.13.x
arch: ppc64le
env:
- TESTTAGS=nomsgpack
- go: 1.14.x
arch: ppc64le
- go: 1.14.x
arch: ppc64le
env:
- TESTTAGS=nomsgpack
- go: 1.15.x
arch: ppc64le
- go: 1.15.x
arch: ppc64le
env:
- TESTTAGS=nomsgpack
- go: master
arch: ppc64le


git:
depth: 10
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS.md
Expand Up @@ -156,7 +156,7 @@ People and companies, who have contributed, in alphabetical order.
- Fix variadic parameter in the flexible render API
- Fix Corrupted plain render
- Add Pluggable View Renderer Example


**@msemenistyi (Mykyta Semenistyi)**
- update Readme.md. Add code to String method
Expand Down
8 changes: 4 additions & 4 deletions BENCHMARKS.md
@@ -1,11 +1,11 @@

# Benchmark System

**VM HOST:** Travis
**Machine:** Ubuntu 16.04.6 LTS x64
**Date:** May 04th, 2020
**VM HOST:** Travis
**Machine:** Ubuntu 16.04.6 LTS x64
**Date:** May 04th, 2020
**Version:** Gin v1.6.3
**Go Version:** 1.14.2 linux/amd64
**Go Version:** 1.14.2 linux/amd64
**Source:** [Go HTTP Router Benchmark](https://github.com/gin-gonic/go-http-routing-benchmark)
**Result:** [See the gist](https://gist.github.com/appleboy/b5f2ecfaf50824ae9c64dcfb9165ae5e) or [Travis result](https://travis-ci.org/github/gin-gonic/go-http-routing-benchmark/jobs/682947061)

Expand Down
10 changes: 5 additions & 5 deletions CHANGELOG.md
Expand Up @@ -215,12 +215,12 @@

## Gin 1.1

- [NEW] Implement QueryArray and PostArray methods
- [NEW] Refactor GetQuery and GetPostForm
- [NEW] Add contribution guide
- [NEW] Implement QueryArray and PostArray methods
- [NEW] Refactor GetQuery and GetPostForm
- [NEW] Add contribution guide
- [FIX] Corrected typos in README
- [FIX] Removed additional Iota
- [FIX] Changed imports to gopkg instead of github in README (#733)
- [FIX] Removed additional Iota
- [FIX] Changed imports to gopkg instead of github in README (#733)
- [FIX] Logger: skip ANSI color commands if output is not a tty

## Gin 1.0rc2 (...)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
@@ -1,4 +1,4 @@
## Contributing
## Contributing

- With issues:
- Use the search tool before opening a new issue.
Expand Down
55 changes: 28 additions & 27 deletions README.md
Expand Up @@ -103,7 +103,7 @@ import "net/http"
```

## Quick start

```sh
# assume the following codes in example.go file
$ cat example.go
Expand Down Expand Up @@ -588,44 +588,44 @@ func main() {
::1 - [Fri, 07 Dec 2018 17:04:38 JST] "GET /ping HTTP/1.1 200 122.767µs "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36" "
```

### Controlling Log output coloring
### Controlling Log output coloring

By default, logs output on console should be colorized depending on the detected TTY.

Never colorize logs:
Never colorize logs:

```go
func main() {
// Disable log's color
gin.DisableConsoleColor()

// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()

router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})

router.Run(":8080")
}
```

Always colorize logs:
Always colorize logs:

```go
func main() {
// Force log's color
gin.ForceConsoleColor()

// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()

router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})

router.Run(":8080")
}
```
Expand Down Expand Up @@ -667,12 +667,12 @@ func main() {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if json.User != "manu" || json.Password != "123" {
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
return
}
}

c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
})

Expand All @@ -688,12 +688,12 @@ func main() {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if xml.User != "manu" || xml.Password != "123" {
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
return
}
}

c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
})

Expand All @@ -705,12 +705,12 @@ func main() {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if form.User != "manu" || form.Password != "123" {
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
return
}
}

c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
})

Expand Down Expand Up @@ -807,7 +807,7 @@ $ curl "localhost:8085/bookable?check_in=2030-03-10&check_out=2030-03-09"
{"error":"Key: 'Booking.CheckOut' Error:Field validation for 'CheckOut' failed on the 'gtfield' tag"}

$ curl "localhost:8085/bookable?check_in=2000-03-09&check_out=2000-03-10"
{"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
{"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
```

[Struct level validations](https://github.com/go-playground/validator/releases/tag/v8.7) can also be registered this way.
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func main() {
data := gin.H{
"foo": "bar",
}

//callback is x
// Will output : x({\"foo\":\"bar\"})
c.JSONP(http.StatusOK, data)
Expand Down Expand Up @@ -1190,21 +1190,21 @@ This feature is unavailable in Go 1.6 and lower.
```go
func main() {
r := gin.Default()

// Serves unicode entities
r.GET("/json", func(c *gin.Context) {
c.JSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})

// Serves literal characters
r.GET("/purejson", func(c *gin.Context) {
c.PureJSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})

// listen and serve on 0.0.0.0:8080
r.Run(":8080")
}
Expand Down Expand Up @@ -1793,8 +1793,8 @@ func main() {
// Initializing the server in a goroutine so that
// it won't block the graceful shutdown handling below
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
log.Printf("listen: %s\n", err)
}
}()

Expand All @@ -1812,10 +1812,11 @@ func main() {
// the request it is currently handling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server forced to shutdown:", err)
}

log.Println("Server exiting")
}
```
Expand Down
3 changes: 2 additions & 1 deletion auth.go
Expand Up @@ -5,6 +5,7 @@
package gin

import (
"crypto/subtle"
"encoding/base64"
"net/http"
"strconv"
Expand All @@ -30,7 +31,7 @@ func (a authPairs) searchCredential(authValue string) (string, bool) {
return "", false
}
for _, pair := range a {
if pair.value == authValue {
if subtle.ConstantTimeCompare([]byte(pair.value), []byte(authValue)) == 1 {
return pair.user, true
}
}
Expand Down
4 changes: 2 additions & 2 deletions debug.go
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
)

const ginSupportMinGoVer = 10
const ginSupportMinGoVer = 12

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

func debugPrintWARNINGDefault() {
if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
debugPrint(`[WARNING] Now Gin requires Go 1.11 or later and Go 1.12 will be required soon.
debugPrint(`[WARNING] Now Gin requires Go 1.12+.
`)
}
Expand Down
2 changes: 1 addition & 1 deletion debug_test.go
Expand Up @@ -104,7 +104,7 @@ func TestDebugPrintWARNINGDefault(t *testing.T) {
})
m, e := getMinVer(runtime.Version())
if e == nil && m <= ginSupportMinGoVer {
assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.11 or later and Go 1.12 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.12+.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
} else {
assert.Equal(t, "[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
}
Expand Down
3 changes: 2 additions & 1 deletion gin_integration_test.go
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -146,7 +147,7 @@ func TestRunWithPort(t *testing.T) {
func TestUnixSocket(t *testing.T) {
router := New()

unixTestSocket := "/tmp/unix_unit_test"
unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test")

defer os.Remove(unixTestSocket)

Expand Down
2 changes: 1 addition & 1 deletion internal/bytesconv/bytesconv.go
Expand Up @@ -9,7 +9,7 @@ import (
)

// StringToBytes converts string to byte slice without a memory allocation.
func StringToBytes(s string) (b []byte) {
func StringToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Expand Down
2 changes: 1 addition & 1 deletion mode.go
Expand Up @@ -63,7 +63,7 @@ func SetMode(value string) {
case TestMode:
ginMode = testCode
default:
panic("gin mode unknown: " + value)
panic("gin mode unknown: " + value + " (available mode: debug release test)")
}

modeName = value
Expand Down

0 comments on commit 5723314

Please sign in to comment.