Skip to content
Permalink
Browse files

Lint with golangci-lint; Fix linter issues; Add Go 1.12 to CircleCI

  • Loading branch information...
DarthSim committed Apr 11, 2019
1 parent 2e6296c commit d5b7e2aa13e9adb82fa72fe32d07cc27ca7e9510
Showing with 101 additions and 15 deletions.
  1. +61 −0 .circleci/config.yml
  2. +22 −0 .golangci.yml
  3. +1 −1 gcs_transport.go
  4. +2 −1 main.go
  5. +3 −5 processing_options.go
  6. +6 −4 processing_options_test.go
  7. +4 −1 s3transport.go
  8. +2 −2 server.go
  9. +0 −1 webp.go
@@ -5,6 +5,41 @@ workflows:
build:
jobs:
- checkout_code
- lint:
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.7"
- build:
name: go1.11_vips8.7
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.7"
- build:
name: go1.11_vips8.6
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.6"
- build:
name: go1.11_vips8.5
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.5"
- build:
name: go1.11_vips8.4
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.4"
- build:
name: go1.11_vips8.3
requires:
- checkout_code
go_version: "1.12"
vips_version: "8.3"
- build:
name: go1.11_vips8.7
requires:
@@ -108,6 +143,32 @@ jobs:
root: .
paths: [.]

lint:
docker:
- image: "darthsim/imgproxy-circleci:latest"
working_directory: /go/src/imgproxy
environment:
BASH_ENV: "/root/.bashrc"
parameters:
go_version:
type: string
vips_version:
type: string
steps:
- attach_workspace:
at: .
- run:
name: Build imgproxy
command: |
gvm install go<< parameters.go_version >> -B
gvm use go<< parameters.go_version >>
export GOPATH=/go
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/vips/<< parameters.vips_version >>/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/vips/<< parameters.vips_version >>/lib/pkgconfig
export CGO_LDFLAGS_ALLOW="-s|-w"
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
golangci-lint run .
build:
docker:
- image: "darthsim/imgproxy-circleci:latest"
@@ -0,0 +1,22 @@
linters:
fast: true
enable:
- golint
- govet
- gosimple
- goconst
- goimports
- staticcheck
disable:
- errcheck

issues:
exclude-rules:
- path: _test\.go
linters:
- goconst

# False positives on CGO generated code
- linters:
- staticcheck
text: "SA4000:"
@@ -45,7 +45,7 @@ func (t gcsTransport) RoundTrip(req *http.Request) (resp *http.Response, err err
ProtoMajor: 1,
ProtoMinor: 0,
Header: make(http.Header),
ContentLength: reader.Size(),
ContentLength: reader.Attrs.Size,
Body: reader,
Close: true,
Request: req,
@@ -5,6 +5,7 @@ import (
"os/signal"
"runtime"
"runtime/debug"
"syscall"
"time"

"net/http"
@@ -39,7 +40,7 @@ func main() {
s := startServer()

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, os.Kill)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)

<-stop

@@ -140,8 +140,6 @@ type processingOptions struct {
UsedPresets []string
}

type applyOptionFunc func(po *processingOptions, args []string) error

const (
imageURLCtxKey = ctxKey("imageUrl")
processingOptionsCtxKey = ctxKey("processingOptions")
@@ -467,19 +465,19 @@ func applyBackgroundOption(po *processingOptions, args []string) error {
case 3:
po.Flatten = true

if r, err := strconv.ParseUint(args[0], 10, 8); err == nil && r >= 0 && r <= 255 {
if r, err := strconv.ParseUint(args[0], 10, 8); err == nil && r <= 255 {
po.Background.R = uint8(r)
} else {
return fmt.Errorf("Invalid background red channel: %s", args[0])
}

if g, err := strconv.ParseUint(args[1], 10, 8); err == nil && g >= 0 && g <= 255 {
if g, err := strconv.ParseUint(args[1], 10, 8); err == nil && g <= 255 {
po.Background.G = uint8(g)
} else {
return fmt.Errorf("Invalid background green channel: %s", args[1])
}

if b, err := strconv.ParseUint(args[2], 10, 8); err == nil && b >= 0 && b <= 255 {
if b, err := strconv.ParseUint(args[2], 10, 8); err == nil && b <= 255 {
po.Background.B = uint8(b)
} else {
return fmt.Errorf("Invalid background blue channel: %s", args[2])
@@ -16,12 +16,14 @@ import (
type ProcessingOptionsTestSuite struct{ MainTestSuite }

func (s *ProcessingOptionsTestSuite) getRequest(url string) *fasthttp.RequestCtx {
req := fasthttp.Request{}
req.SetRequestURI(url)
return &fasthttp.RequestCtx{
Request: req,
ctx := fasthttp.RequestCtx{
Request: fasthttp.Request{},
Response: fasthttp.Response{},
}

ctx.Request.SetRequestURI(url)

return &ctx
}

func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
@@ -25,7 +25,10 @@ func newS3Transport() http.RoundTripper {
s3Conf.S3ForcePathStyle = aws.Bool(true)
}

sess := session.New()
sess, err := session.NewSession()
if err != nil {
logFatal("Can't create S3 session: %s", err)
}

if sess.Config.Region == nil || len(*sess.Config.Region) == 0 {
sess.Config.Region = aws.String("us-west-1")
@@ -262,7 +262,7 @@ func (h *httpHandler) ServeHTTP(rctx *fasthttp.RequestCtx) {
panic(errInvalidMethod)
}

if bytes.Compare(rctx.RequestURI(), healthPath) == 0 {
if bytes.Equal(rctx.RequestURI(), healthPath) {
rctx.SetStatusCode(200)
rctx.SetBody(imgproxyIsRunningMsg)
return
@@ -316,7 +316,7 @@ func (h *httpHandler) ServeHTTP(rctx *fasthttp.RequestCtx) {

rctx.Response.Header.SetBytesV("ETag", eTag)

if bytes.Compare(eTag, rctx.Request.Header.Peek("If-None-Match")) == 0 {
if bytes.Equal(eTag, rctx.Request.Header.Peek("If-None-Match")) {
respondWithNotModified(reqID, rctx)
return
}
@@ -91,7 +91,6 @@ func decodeWebpConfig(r io.Reader) (image.Config, error) {

const alphaBit = 1 << 4

wantAlpha = buf[0] != alphaBit
widthMinusOne := uint32(buf[4]) | uint32(buf[5])<<8 | uint32(buf[6])<<16
heightMinusOne := uint32(buf[7]) | uint32(buf[8])<<8 | uint32(buf[9])<<16

0 comments on commit d5b7e2a

Please sign in to comment.
You can’t perform that action at this time.