Skip to content

Commit 53653b3

Browse files
committed
Merge branch 'master' into fix_router_find_after_invalid_set_param_values
2 parents b166376 + 4422e3b commit 53653b3

29 files changed

+1208
-179
lines changed

.github/stale.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Number of days of inactivity before an issue becomes stale
22
daysUntilStale: 60
33
# Number of days of inactivity before a stale issue is closed
4-
daysUntilClose: 7
4+
daysUntilClose: 30
55
# Issues with these labels will never be considered stale
66
exemptLabels:
77
- pinned
88
- security
9+
- bug
10+
- enhancement
911
# Label to use when marking an issue as stale
10-
staleLabel: wontfix
12+
staleLabel: stale
1113
# Comment to post when marking an issue as stale. Set to `false` to disable
1214
markComment: >
1315
This issue has been automatically marked as stale because it has not had
14-
recent activity. It will be closed if no further activity occurs. Thank you
15-
for your contributions.
16+
recent activity. It will be closed within a month if no further activity occurs.
17+
Thank you for your contributions.
1618
# Comment to post when closing a stale issue. Set to `false` to disable
17-
closeComment: false
19+
closeComment: false

.github/workflows/echo.yml

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ on:
44
push:
55
branches:
66
- master
7+
paths:
8+
- '**.go'
9+
- 'go.*'
10+
- '_fixture/**'
11+
- '.github/**'
12+
- 'codecov.yml'
713
pull_request:
814
branches:
915
- master
10-
11-
env:
12-
GO111MODULE: on
13-
GOPROXY: https://proxy.golang.org
16+
paths:
17+
- '**.go'
18+
- 'go.*'
19+
- '_fixture/**'
20+
- '.github/**'
21+
- 'codecov.yml'
1422

1523
jobs:
1624
test:
1725
strategy:
1826
matrix:
1927
os: [ubuntu-latest, macos-latest, windows-latest]
20-
go: [1.12, 1.13, 1.14]
28+
go: [1.12, 1.13, 1.14, 1.15]
2129
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
2230
runs-on: ${{ matrix.os }}
2331
steps:
@@ -28,10 +36,15 @@ jobs:
2836

2937
- name: Set GOPATH and PATH
3038
run: |
31-
echo "::set-env name=GOPATH::$(dirname $GITHUB_WORKSPACE)"
32-
echo "::add-path::$(dirname $GITHUB_WORKSPACE)/bin"
39+
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
40+
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
3341
shell: bash
3442

43+
- name: Set build variables
44+
run: |
45+
echo "GOPROXY=https://proxy.golang.org" >> $GITHUB_ENV
46+
echo "GO111MODULE=on" >> $GITHUB_ENV
47+
3548
- name: Checkout Code
3649
uses: actions/checkout@v1
3750
with:
@@ -51,3 +64,55 @@ jobs:
5164
with:
5265
token:
5366
fail_ci_if_error: false
67+
benchmark:
68+
needs: test
69+
strategy:
70+
matrix:
71+
os: [ubuntu-latest]
72+
go: [1.15]
73+
name: Benchmark comparison ${{ matrix.os }} @ Go ${{ matrix.go }}
74+
runs-on: ${{ matrix.os }}
75+
steps:
76+
- name: Set up Go ${{ matrix.go }}
77+
uses: actions/setup-go@v1
78+
with:
79+
go-version: ${{ matrix.go }}
80+
81+
- name: Set GOPATH and PATH
82+
run: |
83+
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
84+
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
85+
shell: bash
86+
87+
- name: Set build variables
88+
run: |
89+
echo "GOPROXY=https://proxy.golang.org" >> $GITHUB_ENV
90+
echo "GO111MODULE=on" >> $GITHUB_ENV
91+
92+
- name: Checkout Code (Previous)
93+
uses: actions/checkout@v2
94+
with:
95+
ref: ${{ github.base_ref }}
96+
path: previous
97+
98+
- name: Checkout Code (New)
99+
uses: actions/checkout@v2
100+
with:
101+
path: new
102+
103+
- name: Install Dependencies
104+
run: go get -v golang.org/x/perf/cmd/benchstat
105+
106+
- name: Run Benchmark (Previous)
107+
run: |
108+
cd previous
109+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
110+
111+
- name: Run Benchmark (New)
112+
run: |
113+
cd new
114+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
115+
116+
- name: Run Benchstat
117+
run: |
118+
benchstat previous/benchmark.txt new/benchmark.txt

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
arch:
2+
- amd64
3+
- ppc64le
4+
15
language: go
26
go:
37
- 1.14.x

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ For older versions, please use the latest v3 tag.
4242

4343
## Benchmarks
4444

45-
Date: 2018/03/15<br>
45+
Date: 2020/11/11<br>
4646
Source: https://github.com/vishr/web-framework-benchmark<br>
4747
Lower is better!
4848

49-
<img src="https://i.imgur.com/I32VdMJ.png">
49+
<img src="https://i.imgur.com/qwPNQbl.png">
50+
<img src="https://i.imgur.com/s8yKQjx.png">
51+
52+
The benchmarks above were run on an Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
5053

5154
## [Guide](https://echo.labstack.com/guide)
5255

_fixture/_fixture/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used for the static middleware test

codecov.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
threshold: 1%
6+
patch:
7+
default:
8+
threshold: 1%
9+
10+
comment:
11+
require_changes: true

context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
385385
if err != nil {
386386
return nil, err
387387
}
388-
defer f.Close()
388+
f.Close()
389389
return fh, nil
390390
}
391391

echo.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import (
4949
"net/http"
5050
"net/url"
5151
"os"
52-
"path"
5352
"path/filepath"
5453
"reflect"
5554
"runtime"
@@ -92,6 +91,7 @@ type (
9291
Renderer Renderer
9392
Logger Logger
9493
IPExtractor IPExtractor
94+
ListenerNetwork string
9595
}
9696

9797
// Route contains a handler and information for matching against requests.
@@ -281,6 +281,7 @@ var (
281281
ErrInvalidRedirectCode = errors.New("invalid redirect status code")
282282
ErrCookieNotFound = errors.New("cookie not found")
283283
ErrInvalidCertOrKeyType = errors.New("invalid cert or key type, must be string or []byte")
284+
ErrInvalidListenerNetwork = errors.New("invalid listener network")
284285
)
285286

286287
// Error handlers
@@ -302,9 +303,10 @@ func New() (e *Echo) {
302303
AutoTLSManager: autocert.Manager{
303304
Prompt: autocert.AcceptTOS,
304305
},
305-
Logger: log.New("echo"),
306-
colorer: color.New(),
307-
maxParam: new(int),
306+
Logger: log.New("echo"),
307+
colorer: color.New(),
308+
maxParam: new(int),
309+
ListenerNetwork: "tcp",
308310
}
309311
e.Server.Handler = e
310312
e.TLSServer.Handler = e
@@ -362,10 +364,12 @@ func (e *Echo) DefaultHTTPErrorHandler(err error, c Context) {
362364
// Issue #1426
363365
code := he.Code
364366
message := he.Message
365-
if e.Debug {
366-
message = err.Error()
367-
} else if m, ok := message.(string); ok {
368-
message = Map{"message": m}
367+
if m, ok := he.Message.(string); ok {
368+
if e.Debug {
369+
message = Map{"message": m, "error": err.Error()}
370+
} else {
371+
message = Map{"message": m}
372+
}
369373
}
370374

371375
// Send response
@@ -481,7 +485,7 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl
481485
return err
482486
}
483487

484-
name := filepath.Join(root, path.Clean("/"+p)) // "/"+ for security
488+
name := filepath.Join(root, filepath.Clean("/"+p)) // "/"+ for security
485489
fi, err := os.Stat(name)
486490
if err != nil {
487491
// The access path does not exist
@@ -570,7 +574,7 @@ func (e *Echo) Reverse(name string, params ...interface{}) string {
570574
for _, r := range e.router.routes {
571575
if r.Name == name {
572576
for i, l := 0, len(r.Path); i < l; i++ {
573-
if r.Path[i] == ':' && n < ln {
577+
if (r.Path[i] == ':' || r.Path[i] == '*') && n < ln {
574578
for ; i < l && r.Path[i] != '/'; i++ {
575579
}
576580
uri.WriteString(fmt.Sprintf("%v", params[n]))
@@ -712,7 +716,7 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
712716

713717
if s.TLSConfig == nil {
714718
if e.Listener == nil {
715-
e.Listener, err = newListener(s.Addr)
719+
e.Listener, err = newListener(s.Addr, e.ListenerNetwork)
716720
if err != nil {
717721
return err
718722
}
@@ -723,7 +727,7 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
723727
return s.Serve(e.Listener)
724728
}
725729
if e.TLSListener == nil {
726-
l, err := newListener(s.Addr)
730+
l, err := newListener(s.Addr, e.ListenerNetwork)
727731
if err != nil {
728732
return err
729733
}
@@ -752,7 +756,7 @@ func (e *Echo) StartH2CServer(address string, h2s *http2.Server) (err error) {
752756
}
753757

754758
if e.Listener == nil {
755-
e.Listener, err = newListener(s.Addr)
759+
e.Listener, err = newListener(s.Addr, e.ListenerNetwork)
756760
if err != nil {
757761
return err
758762
}
@@ -873,8 +877,11 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
873877
return
874878
}
875879

876-
func newListener(address string) (*tcpKeepAliveListener, error) {
877-
l, err := net.Listen("tcp", address)
880+
func newListener(address, network string) (*tcpKeepAliveListener, error) {
881+
if network != "tcp" && network != "tcp4" && network != "tcp6" {
882+
return nil, ErrInvalidListenerNetwork
883+
}
884+
l, err := net.Listen(network, address)
878885
if err != nil {
879886
return nil, err
880887
}

0 commit comments

Comments
 (0)