Skip to content

Commit

Permalink
chore: Add golangci (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy authored Jun 19, 2021
1 parent 2cd427d commit e89e167
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
with:
ref: ${{ github.ref }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v2

- name: Run Tests
run: |
go test -v -covermode=atomic -coverprofile=coverage.out
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Timeout wraps a handler and aborts the process of the handler if the timeout is
package main

import (
"log"
"net/http"
"time"

Expand All @@ -35,8 +36,11 @@ func main() {
))

// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}

```

### custom error response
Expand Down
5 changes: 4 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"net/http"
"time"

Expand All @@ -22,5 +23,7 @@ func main() {
))

// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
8 changes: 4 additions & 4 deletions timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ type Timeout struct {
response gin.HandlerFunc
}

var (
buffpool *BufferPool
)
var buffpool *BufferPool

// New wraps a handler and aborts the process of the handler if the timeout is reached
func New(opts ...Option) gin.HandlerFunc {
Expand Down Expand Up @@ -104,7 +102,9 @@ func New(opts ...Option) gin.HandlerFunc {
dst[k] = vv
}
tw.ResponseWriter.WriteHeader(tw.code)
tw.ResponseWriter.Write(buffer.Bytes())
if _, err := tw.ResponseWriter.Write(buffer.Bytes()); err != nil {
panic(err)
}
tw.FreeBuffer()
buffpool.Put(buffer)

Expand Down

0 comments on commit e89e167

Please sign in to comment.