Skip to content

Commit

Permalink
Fix various issues to make newer golangci-lint happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Hopkins authored and aaron42net committed Jun 20, 2023
1 parent eb68f07 commit 0949050
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 23 deletions.
6 changes: 2 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
# - depguard
- errcheck
- errorlint
- exhaustive
Expand All @@ -42,11 +41,10 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- tparallel
- typecheck
- unconvert
- varcheck
- unused
- wastedassign

fast: false
Expand Down
13 changes: 10 additions & 3 deletions cmd/fotomat/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
"os"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand All @@ -34,7 +35,13 @@ func TestMain(m *testing.M) {
// Record that address.
localhost = listen.Addr().String()

go func() { _ = http.Serve(listen, handleInit()) }()
go func() {
srv := &http.Server{
Handler: handleInit(),
ReadTimeout: 10 * time.Second,
}
_ = srv.Serve(listen)
}()

vips.Initialize()
vips.LeakSet(true)
Expand Down Expand Up @@ -133,7 +140,7 @@ func fetch(filename string) ([]byte, int) {

defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/fotomat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ func main() {
}

if *debugListen != "" {
http.Handle("/metrics", promhttp.Handler())
go func() { log.Fatal(http.ListenAndServe(*debugListen, nil)) }()
go func() {
ps := &http.Server{
Addr: *debugListen,
Handler: promhttp.Handler(),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 5 * time.Minute,
}
log.Fatal(ps.ListenAndServe())
}()
}

handler := handleInit()
Expand Down
3 changes: 1 addition & 2 deletions format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package format

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -48,7 +47,7 @@ func metadataError(filename string) error {
}

func image(filename string) []byte {
bytes, err := ioutil.ReadFile(TestdataPath + filename)
bytes, err := os.ReadFile(TestdataPath + filename)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion thumbnail/icc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
func init() {
d := path.Join(os.TempDir(), "fotomat_temp-"+strconv.Itoa(os.Getuid()), "icc")

if err := os.MkdirAll(d, 0700); err != nil {
if err := os.MkdirAll(d, 0o700); err != nil {
log.Fatalln("Can't create directory", d, err)
}

Expand Down
8 changes: 4 additions & 4 deletions thumbnail/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, or *http.Request) {
}

func (p *Proxy) get(ctx context.Context, url string, header http.Header) ([]byte, http.Header, int, error) {
r, err := http.NewRequest("GET", url, nil)
r, err := http.NewRequest("GET", url, http.NoBody)
if err != nil {
return nil, nil, 0, err
}
Expand All @@ -139,7 +139,7 @@ func (p *Proxy) get(ctx context.Context, url string, header http.Header) ([]byte
return nil, nil, 0, err
}

orig, err := ioutil.ReadAll(resp.Body)
orig, err := io.ReadAll(resp.Body)
_ = resp.Body.Close()

return orig, resp.Header, resp.StatusCode, err
Expand Down Expand Up @@ -204,7 +204,7 @@ func proxyError(w http.ResponseWriter, err error, status int) {
}

if err == nil {
err = fmt.Errorf(http.StatusText(status))
err = errors.New(http.StatusText(status))
}

http.Error(w, err.Error(), status)
Expand Down
4 changes: 2 additions & 2 deletions thumbnail/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package thumbnail

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -115,7 +115,7 @@ func (ps *proxyServer) get(filename string) ([]byte, int) {
panic(err)
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
panic(err)
Expand Down
3 changes: 1 addition & 2 deletions thumbnail/thumbnail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package thumbnail

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -424,7 +423,7 @@ func isSize(image []byte, f format.Format, width, height int, alpha bool) error
}

func image(filename string) []byte {
bytes, err := ioutil.ReadFile("../testdata/" + filename)
bytes, err := os.ReadFile("../testdata/" + filename)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion vips/convolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (in *Image) Gaussblur(sigma float64) error {

// PhotoMetric takes a histogram of a Sobel edge detect of our image.
// Returns the highest number of histogram values in a row that are more
// than the maximum value * threshhold. With a threshold of 0.01, more than
// than the maximum value * threshold. With a threshold of 0.01, more than
// 16 indicates a photo.
func (in *Image) PhotoMetric(threshold float64) (int, error) {
var out C.int
Expand Down
6 changes: 4 additions & 2 deletions vips/resample.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func (i *Interpolate) Close() {

// Affine performs this affine transform on the input image using the
// supplied interpolate:
// X = a * (x + idx ) + b * (y + idy ) + odx
// Y = c * (x + idx ) + d * (y + idy ) + doy
//
// X = a * (x + idx ) + b * (y + idy ) + odx
// Y = c * (x + idx ) + d * (y + idy ) + doy
//
// x and y are the coordinates in input image. X and Y are the coordinates
// in output image. (0,0) is the upper left corner.
func (in *Image) Affine(a, b, c, d float64, interpolate *Interpolate) error {
Expand Down
1 change: 1 addition & 0 deletions vips/vips_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// "-tags vips_static" build flag is used. Configure VIPS with:
// CFLAGS="-fPIE" CXXFLAGS="-fPIE" LDFLAGS="-lstdc++"

//go:build vips_static
// +build vips_static

package vips
Expand Down

0 comments on commit 0949050

Please sign in to comment.