Skip to content

Commit 89ec007

Browse files
authored
Merge branch 'master' into fix-conflict
2 parents 13374d1 + 4422e3b commit 89ec007

24 files changed

+1120
-108
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
@@ -365,7 +365,7 @@ func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
365365
if err != nil {
366366
return nil, err
367367
}
368-
defer f.Close()
368+
f.Close()
369369
return fh, nil
370370
}
371371

echo.go

Lines changed: 16 additions & 11 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
@@ -483,7 +485,7 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl
483485
return err
484486
}
485487

486-
name := filepath.Join(root, path.Clean("/"+p)) // "/"+ for security
488+
name := filepath.Join(root, filepath.Clean("/"+p)) // "/"+ for security
487489
fi, err := os.Stat(name)
488490
if err != nil {
489491
// The access path does not exist
@@ -573,7 +575,7 @@ func (e *Echo) Reverse(name string, params ...interface{}) string {
573575
for _, r := range e.router.routes {
574576
if r.Name == name {
575577
for i, l := 0, len(r.Path); i < l; i++ {
576-
if r.Path[i] == ':' && n < ln {
578+
if (r.Path[i] == ':' || r.Path[i] == '*') && n < ln {
577579
for ; i < l && r.Path[i] != '/'; i++ {
578580
}
579581
uri.WriteString(fmt.Sprintf("%v", params[n]))
@@ -715,7 +717,7 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
715717

716718
if s.TLSConfig == nil {
717719
if e.Listener == nil {
718-
e.Listener, err = newListener(s.Addr)
720+
e.Listener, err = newListener(s.Addr, e.ListenerNetwork)
719721
if err != nil {
720722
return err
721723
}
@@ -726,7 +728,7 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
726728
return s.Serve(e.Listener)
727729
}
728730
if e.TLSListener == nil {
729-
l, err := newListener(s.Addr)
731+
l, err := newListener(s.Addr, e.ListenerNetwork)
730732
if err != nil {
731733
return err
732734
}
@@ -755,7 +757,7 @@ func (e *Echo) StartH2CServer(address string, h2s *http2.Server) (err error) {
755757
}
756758

757759
if e.Listener == nil {
758-
e.Listener, err = newListener(s.Addr)
760+
e.Listener, err = newListener(s.Addr, e.ListenerNetwork)
759761
if err != nil {
760762
return err
761763
}
@@ -876,8 +878,11 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
876878
return
877879
}
878880

879-
func newListener(address string) (*tcpKeepAliveListener, error) {
880-
l, err := net.Listen("tcp", address)
881+
func newListener(address, network string) (*tcpKeepAliveListener, error) {
882+
if network != "tcp" && network != "tcp4" && network != "tcp6" {
883+
return nil, ErrInvalidListenerNetwork
884+
}
885+
l, err := net.Listen(network, address)
881886
if err != nil {
882887
return nil, err
883888
}

0 commit comments

Comments
 (0)