Skip to content

Commit

Permalink
Cleanup receiver names and remove most nolints (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane authored Sep 27, 2023
1 parent b3392da commit 72857a0
Show file tree
Hide file tree
Showing 21 changed files with 848 additions and 851 deletions.
18 changes: 17 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ issues:
# checks from err113 are useful.
- "err113: do not define dynamic errors.*"
exclude-rules:
- path: internal/examples/pets/.*\.go
- path: internal/examples/.*/.*\.go
linters:
- forbidigo # log.Fatal, fmt.Printf used in example programs
- gosec
- gochecknoglobals
- path: ".*_test.go"
linters:
- dupl # allow duplicate string literals for testing
- forcetypeassert
- nilerr # allow encoding error and returning nil
- path: vanguard_examples_test.go
linters:
- gocritic # allow log.Fatal for examples
- path: handler.go
linters:
- contextcheck # use request context
- path: params.go
linters:
- goconst # allow string literals for WKT names
15 changes: 6 additions & 9 deletions buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ type bufferPool struct {
}

func newBufferPool() *bufferPool {
return &bufferPool{
Pool: sync.Pool{
New: func() any {
return bytes.NewBuffer(make([]byte, 0, initialBufferSize))
},
},
}
return &bufferPool{}
}

func (b *bufferPool) Get() *bytes.Buffer {
return b.Pool.Get().(*bytes.Buffer) //nolint:forcetypeassert
if buffer, ok := b.Pool.Get().(*bytes.Buffer); ok {
buffer.Reset()
return buffer
}
return bytes.NewBuffer(make([]byte, 0, initialBufferSize))
}

func (b *bufferPool) Put(buffer *bytes.Buffer) {
if buffer.Cap() > maxRecycleBufferSize {
return
}
buffer.Reset()
b.Pool.Put(buffer)
}

Expand Down
4 changes: 2 additions & 2 deletions compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *compressionPool) compress(dst, src *bytes.Buffer) error {
if src.Len() == 0 {
return nil
}
comp := p.compressors.Get().(connect.Compressor) //nolint:forcetypeassert,errcheck
comp, _ := p.compressors.Get().(connect.Compressor)
defer p.compressors.Put(comp)

comp.Reset(dst)
Expand All @@ -91,7 +91,7 @@ func (p *compressionPool) decompress(dst, src *bytes.Buffer) error {
if src.Len() == 0 {
return nil
}
decomp := p.decompressors.Get().(connect.Decompressor) //nolint:forcetypeassert,errcheck
decomp, _ := p.decompressors.Get().(connect.Decompressor)
defer p.decompressors.Put(decomp)

if err := decomp.Reset(src); err != nil {
Expand Down
Loading

0 comments on commit 72857a0

Please sign in to comment.