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

Commit

Permalink
chore: update go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 7, 2019
1 parent 6e695ad commit b5498d7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ sudo: required

go:
- "1.12"
- "1.13"
- master

script:
- make test
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
- make lint && make test
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ bench:
go test -bench=. ./...

release:
go mod tidy
go mod tidy

lint:
golangci-lint run
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (

func main() {

d := elton.New()
d.Use(etag.NewDefault())
e := elton.New()
e.Use(etag.NewDefault())

d.GET("/", func(c *elton.Context) (err error) {
e.GET("/", func(c *elton.Context) (err error) {
c.BodyBuffer = bytes.NewBufferString("abcd")
return
})

d.ListenAndServe(":7001")
e.ListenAndServe(":3000")
}

```
Expand Down
9 changes: 7 additions & 2 deletions etag.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func gen(buf []byte) string {
return `"0-2jmj7l5rSw0yVb_vlWAYkK_YBwk="`
}
h := sha1.New()
h.Write(buf)
_, err := h.Write(buf)
if err != nil {
return ""
}
hash := base64.URLEncoding.EncodeToString(h.Sum(nil))
return fmt.Sprintf(`"%x-%s"`, size, hash)
}
Expand Down Expand Up @@ -77,7 +80,9 @@ func New(config Config) elton.Handler {
return
}
eTag := gen(bodyBuf.Bytes())
c.SetHeader(elton.HeaderETag, eTag)
if eTag != "" {
c.SetHeader(elton.HeaderETag, eTag)
}
return
}
}
2 changes: 1 addition & 1 deletion etag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func BenchmarkMd5(b *testing.B) {
return `"0-2jmj7l5rSw0yVb_vlWAYkK_YBwk="`
}
h := md5.New()
h.Write(buf)
_, _ = h.Write(buf)
hash := base64.URLEncoding.EncodeToString(h.Sum(nil))
return fmt.Sprintf(`"%x-%s"`, size, hash)
}
Expand Down
24 changes: 24 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"bytes"

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

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

e.Use(etag.NewDefault())

e.GET("/", func(c *elton.Context) (err error) {
c.BodyBuffer = bytes.NewBufferString("abcd")
return
})

err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/vicanso/elton-etag
go 1.12

require (
github.com/stretchr/testify v1.3.0
github.com/vicanso/elton v0.2.0
github.com/stretchr/testify v1.4.0
github.com/vicanso/elton v0.2.1
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
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.0 h1:QlXgmq6m+9wZN7FeLD25/EhBkl8blzppviVY5U5PTm0=
github.com/vicanso/elton v0.2.0/go.mod h1:ynAUOSkZQ+pFaUsxlG5hYnJFjPpMwz8YyEBPzNh0pSg=
github.com/vicanso/elton v0.2.1 h1:OrfDjNjXL6KzUhAuAFwCQIa6guXXd7OY+L4ZgH16Rpc=
github.com/vicanso/elton v0.2.1/go.mod h1:ynAUOSkZQ+pFaUsxlG5hYnJFjPpMwz8YyEBPzNh0pSg=
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/keygrip v0.1.0 h1:/zYzoVIbREAvaxSM7bo3/oSXuuYztaP71dPBfhRoNkM=
github.com/vicanso/keygrip v0.1.0/go.mod h1:cI05iOjY00NJ7oH2Z9Zdm9eJPUkpoex3XnEubK78nho=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit b5498d7

Please sign in to comment.