Skip to content

Commit

Permalink
chore: update go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 15, 2021
1 parent 069bcda commit b131f9b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 17 deletions.
6 changes: 6 additions & 0 deletions elton.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"time"

"github.com/vicanso/hes"
intranetip "github.com/vicanso/intranet-ip"
)

const (
Expand Down Expand Up @@ -161,6 +162,11 @@ func NewGroup(path string, handlerList ...Handler) *Group {
}
}

// IsIntranet check ip is intranet
func IsIntranet(ip string) bool {
return intranetip.Is(net.ParseIP(ip))
}

// SetFunctionName set function name
func (e *Elton) SetFunctionName(fn interface{}, name string) {
p := reflect.ValueOf(fn).Pointer()
Expand Down
10 changes: 9 additions & 1 deletion elton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ import (
"github.com/vicanso/hes"
)

func TestIntranet(t *testing.T) {
assert := assert.New(t)

assert.True(IsIntranet("127.0.0.1"))
assert.True(IsIntranet("192.168.1.1"))
assert.False(IsIntranet("1.1.1.1"))
}

func TestSkipper(t *testing.T) {
c := &Context{
Committed: true,
Expand Down Expand Up @@ -296,7 +304,7 @@ func TestHandle(t *testing.T) {
resp := httptest.NewRecorder()
e.ServeHTTP(resp, req)
assert.Equal(http.StatusBadRequest, resp.Code, "default hes error status code should be 400")
assert.Equal("message=abcd", resp.Body.String())
assert.Equal("statusCode=400, message=abcd", resp.Body.String())
})

t.Run("get routers", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.12

require (
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.6.7
github.com/tidwall/gjson v1.6.8
github.com/vicanso/fresh v1.0.0
github.com/vicanso/hes v0.3.0
github.com/vicanso/hes v0.3.5
github.com/vicanso/intranet-ip v0.0.1
github.com/vicanso/keygrip v1.1.0
)
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.6.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE=
github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/vicanso/fresh v1.0.0 h1:u3ykbW6SYW5CbI6rx1lZCVfWKVIptvL6/2KOnrTKsTY=
github.com/vicanso/fresh v1.0.0/go.mod h1:gr1RKSFxQ1OnQHzUMBHCigifni7KrXveJjWCTlPjICA=
github.com/vicanso/hes v0.3.0 h1:atgM8+nBBdti7Ru0R84I7yh4fY4Yy9Ykq0K5EhMk77c=
github.com/vicanso/hes v0.3.0/go.mod h1:QcxOFmFfBQMhASTaLgnFayXYCgevdSeBVprt+o+3eKo=
github.com/vicanso/hes v0.3.5 h1:QPJRP4ks7W7gpIgzOzb6aaUafY8qWjmlcFdgOiqLflY=
github.com/vicanso/hes v0.3.5/go.mod h1:B0l1NIQM/nYw7owAd+hyHuNnAD8Nsx0T6duhVxmXUBY=
github.com/vicanso/intranet-ip v0.0.1 h1:cYS+mExFsKqewWSuHtFwAqw/CO66GsheB/P1BPmSTx0=
github.com/vicanso/intranet-ip v0.0.1/go.mod h1:bqQ6VUhxdz0ipSb1kzd6aoZStlp+pB7CTlVmVhgLAxA=
github.com/vicanso/keygrip v1.1.0 h1:B+qtNe/vvgZbYlkbJC4cOsbY9MzNp23+m2+ZybRy45Q=
Expand Down
2 changes: 1 addition & 1 deletion middleware/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestErrorHandler(t *testing.T) {
return c
},
fn: defaultErrorHandler,
result: bytes.NewBufferString(`category=elton-error, message=abcd`),
result: bytes.NewBufferString(`statusCode=500, category=elton-error, message=abcd`),
cacheControl: "public, max-age=300",
contentType: "text/plain; charset=utf-8",
},
Expand Down
7 changes: 4 additions & 3 deletions middleware/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ func TestProxy(t *testing.T) {
Transport: &http.Transport{},
}),
err: &hes.Error{
Category: ErrProxyCategory,
Message: "dial tcp 127.0.0.1:443: connect: connection refused",
Exception: true,
Category: ErrProxyCategory,
StatusCode: 400,
Message: "dial tcp 127.0.0.1:443: connect: connection refused",
Exception: true,
},
target: "https://127.0.0.1",
},
Expand Down
2 changes: 1 addition & 1 deletion middleware/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestRecoverResponseText(t *testing.T) {

e.ServeHTTP(resp, req)
assert.Equal(http.StatusInternalServerError, resp.Code)
assert.Equal("category=elton-recover, message=abc", resp.Body.String())
assert.Equal("statusCode=500, category=elton-recover, message=abc", resp.Body.String())
assert.True(ctx.Committed)
assert.True(catchError)
for _, key := range keys {
Expand Down
7 changes: 4 additions & 3 deletions middleware/responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ func TestResponder(t *testing.T) {
return c
},
err: &hes.Error{
Message: "json: unsupported type: func()",
Category: ErrResponderCategory,
Exception: true,
Message: "json: unsupported type: func()",
StatusCode: 500,
Category: ErrResponderCategory,
Exception: true,
},
},
// response string
Expand Down
2 changes: 1 addition & 1 deletion middleware/static_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestStaticServe(t *testing.T) {
}
return c
},
err: errors.New("category=elton-static-serve, message=abcd"),
err: errors.New("statusCode=500, category=elton-static-serve, message=abcd"),
},
// image
{
Expand Down

0 comments on commit b131f9b

Please sign in to comment.