Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Commit

Permalink
chore: update modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Jan 1, 2020
1 parent df2d284 commit efe2234
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ Recover middleware for elton, it can get panic error to avoid application crash.
package main

import (
"errors"

"github.com/vicanso/elton"

recover "github.com/vicanso/elton-recover"
)

func main() {
d := elton.New()
e := elton.New()

d.Use(recover.New())
e.Use(recover.New())

d.GET("/", func(c *elton.Context) (err error) {
panic("abcd")
e.GET("/", func(c *elton.Context) (err error) {
panic(errors.New("abcd"))
})

d.ListenAndServe(":3000")
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}

```
12 changes: 7 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package main

import (
"errors"

"github.com/vicanso/elton"

recover "github.com/vicanso/elton-recover"
)

func main() {
d := elton.New()
e := elton.New()

d.Use(recover.New())
e.Use(recover.New())

d.GET("/", func(c *elton.Context) (err error) {
panic("abcd")
e.GET("/", func(c *elton.Context) (err error) {
panic(errors.New("abcd"))
})

err := d.ListenAndServe(":3000")
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.12

require (
github.com/stretchr/testify v1.4.0
github.com/vicanso/elton v0.2.2
github.com/vicanso/elton v0.2.3
github.com/vicanso/hes v0.2.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/vicanso/elton v0.2.2 h1:MZ5nfJFKBWDWnFPO8wRyPat8kZz3KoNBY0scemo7RFQ=
github.com/vicanso/elton v0.2.2/go.mod h1:QFZ+Un4LLBANtl0mExkqLD4uqw3JLA2ZCWUHaCsHOUg=
github.com/vicanso/elton v0.2.3 h1:XQskGFtw/hhtNXRU7dLX0OFcpG64pK4PMXh9CVjHVbA=
github.com/vicanso/elton v0.2.3/go.mod h1:QFZ+Un4LLBANtl0mExkqLD4uqw3JLA2ZCWUHaCsHOUg=
github.com/vicanso/hes v0.2.1 h1:jRFEADmiQ30koVY/sKwlkhyXM5B3QbVVizLqrjNJgPw=
github.com/vicanso/hes v0.2.1/go.mod h1:QcxOFmFfBQMhASTaLgnFayXYCgevdSeBVprt+o+3eKo=
github.com/vicanso/intranet-ip v0.0.1 h1:cYS+mExFsKqewWSuHtFwAqw/CO66GsheB/P1BPmSTx0=
Expand Down
18 changes: 9 additions & 9 deletions recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func TestRecover(t *testing.T) {
t.Run("response text", func(t *testing.T) {
assert := assert.New(t)
var ctx *elton.Context
d := elton.New()
d.Use(New())
d.GET("/", func(c *elton.Context) error {
e := elton.New()
e.Use(New())
e.GET("/", func(c *elton.Context) error {
ctx = c
panic("abc")
})
Expand All @@ -34,11 +34,11 @@ func TestRecover(t *testing.T) {
}

catchError := false
d.OnError(func(_ *elton.Context, _ error) {
e.OnError(func(_ *elton.Context, _ error) {
catchError = true
})

d.ServeHTTP(resp, req)
e.ServeHTTP(resp, req)
assert.Equal(resp.Code, http.StatusInternalServerError)
assert.Equal(resp.Body.String(), "category=elton-recover, message=abc")
assert.True(ctx.Committed)
Expand All @@ -50,15 +50,15 @@ func TestRecover(t *testing.T) {

t.Run("response json", func(t *testing.T) {
assert := assert.New(t)
d := elton.New()
d.Use(New())
d.GET("/", func(c *elton.Context) error {
e := elton.New()
e.Use(New())
e.GET("/", func(c *elton.Context) error {
panic("abc")
})
req := httptest.NewRequest("GET", "https://aslant.site/", nil)
req.Header.Set("Accept", "application/json, text/plain, */*")
resp := httptest.NewRecorder()
d.ServeHTTP(resp, req)
e.ServeHTTP(resp, req)
assert.Equal(500, resp.Code)
assert.Equal(elton.MIMEApplicationJSON, resp.Header().Get(elton.HeaderContentType))
assert.NotEmpty(resp.Body.Bytes())
Expand Down

0 comments on commit efe2234

Please sign in to comment.