Skip to content

Commit 3d81a7a

Browse files
committed
Linting
1 parent f9281b1 commit 3d81a7a

File tree

8 files changed

+83
-92
lines changed

8 files changed

+83
-92
lines changed

Makefile

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
11
.PHONY: lint
22
lint:
3-
@echo Installing linters...
4-
go get -u github.com/pavius/impi/cmd/impi
5-
go get -u gopkg.in/alecthomas/gometalinter.v2
6-
@$(GOPATH)/bin/gometalinter.v2 --install
7-
8-
@echo Verifying imports...
9-
$(GOPATH)/bin/impi \
10-
--local github.com/v3io/v3io-go \
11-
--scheme stdLocalThirdParty \
12-
./cmd/... ./controlplane/... ./internal/...
13-
14-
@echo Linting...
15-
@$(GOPATH)/bin/gometalinter.v2 \
16-
--deadline=300s \
17-
--disable-all \
18-
--enable-gc \
19-
--enable=deadcode \
20-
--enable=goconst \
21-
--enable=gofmt \
22-
--enable=golint \
23-
--enable=gosimple \
24-
--enable=ineffassign \
25-
--enable=interfacer \
26-
--enable=misspell \
27-
--enable=staticcheck \
28-
--enable=unconvert \
29-
--enable=varcheck \
30-
--enable=vet \
31-
--enable=vetshadow \
32-
--enable=errcheck \
33-
--exclude="_test.go" \
34-
--exclude="comment on" \
35-
--exclude="error should be the last" \
36-
--exclude="should have comment" \
37-
--skip=pkg/platform/kube/apis \
38-
--skip=pkg/platform/kube/client \
39-
./cmd/... ./controlplane/... ./internal/...
3+
docker run --rm \
4+
--volume ${shell pwd}:/go/src/github.com/v3io/v3io-go \
5+
--env GOPATH=/go \
6+
--env GO111MODULE=off \
7+
golang:1.12 \
8+
bash /go/src/github.com/v3io/v3io-go/hack/lint.sh
409

4110
@echo Done.

hack/lint.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
set -e
2+
3+
cd $GOPATH/src/github.com/v3io/v3io-go
4+
5+
echo Installing impi
6+
go get -u github.com/pavius/impi/cmd/impi
7+
8+
echo Linting imports with impi
9+
$GOPATH/bin/impi \
10+
--local github.com/v3io/v3io-go \
11+
--scheme stdLocalThirdParty \
12+
./pkg/...
13+
14+
echo Getting all packages
15+
go get ./...
16+
17+
echo Installing gometalinter
18+
go get -u gopkg.in/alecthomas/gometalinter.v2
19+
$GOPATH/bin/gometalinter.v2 --install
20+
21+
echo Linting with gometalinter
22+
$GOPATH/bin/gometalinter.v2 \
23+
--deadline=300s \
24+
--disable-all \
25+
--enable-gc \
26+
--enable=deadcode \
27+
--enable=goconst \
28+
--enable=gofmt \
29+
--enable=golint \
30+
--enable=gosimple \
31+
--enable=ineffassign \
32+
--enable=interfacer \
33+
--enable=misspell \
34+
--enable=staticcheck \
35+
--enable=unconvert \
36+
--enable=varcheck \
37+
--enable=vet \
38+
--enable=vetshadow \
39+
--enable=errcheck \
40+
--exclude="_test.go" \
41+
--exclude="comment on" \
42+
--exclude="error should be the last" \
43+
--exclude="should have comment" \
44+
--skip=pkg/platform/kube/apis \
45+
--skip=pkg/platform/kube/client \
46+
./pkg/...

pkg/controlplane/http/session.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,14 @@ func (s *session) createResource(ctx context.Context,
176176
controlPlaneOutput *v3ioc.ControlPlaneOutput,
177177
responseAttributes interface{}) error {
178178

179-
if err := s.createOrUpdateResource(ctx,
179+
return s.createOrUpdateResource(ctx,
180180
path,
181181
http.MethodPost,
182182
kind,
183183
controlPlaneInput,
184184
requestAttributes,
185185
controlPlaneOutput,
186-
responseAttributes); err != nil {
187-
return err
188-
}
189-
return nil
186+
responseAttributes)
190187
}
191188

192189
func (s *session) updateResource(ctx context.Context,
@@ -197,18 +194,14 @@ func (s *session) updateResource(ctx context.Context,
197194
responseID *v3ioc.ControlPlaneOutput,
198195
responseAttributes interface{}) error {
199196

200-
if err := s.createOrUpdateResource(ctx,
197+
return s.createOrUpdateResource(ctx,
201198
path,
202199
http.MethodPut,
203200
kind,
204201
controlPlaneInput,
205202
requestAttributes,
206203
responseID,
207-
responseAttributes); err != nil {
208-
return err
209-
}
210-
return nil
211-
204+
responseAttributes)
212205
}
213206

214207
func (s *session) createOrUpdateResource(ctx context.Context,

pkg/dataplane/http/context.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
// TODO: Request should have a global pool
27-
var requestID uint64 = 0
27+
var requestID uint64
2828

2929
type context struct {
3030
logger logger.Logger
@@ -210,7 +210,7 @@ func (c *context) GetItemsSync(getItemsInput *v3io.GetItemsInput) (*v3io.Respons
210210
"PUT",
211211
getItemsInput.Path,
212212
getItemsHeaders,
213-
[]byte(marshalledBody),
213+
marshalledBody,
214214
false)
215215

216216
if err != nil {
@@ -393,11 +393,7 @@ func (c *context) PutObjectSync(putObjectInput *v3io.PutObjectInput) error {
393393
putObjectInput.Body,
394394
true)
395395

396-
if err != nil {
397-
return err
398-
}
399-
400-
return nil
396+
return err
401397
}
402398

403399
// DeleteObject
@@ -416,11 +412,7 @@ func (c *context) DeleteObjectSync(deleteObjectInput *v3io.DeleteObjectInput) er
416412
nil,
417413
true)
418414

419-
if err != nil {
420-
return err
421-
}
422-
423-
return nil
415+
return err
424416
}
425417

426418
// CreateStream
@@ -443,11 +435,7 @@ func (c *context) CreateStreamSync(createStreamInput *v3io.CreateStreamInput) er
443435
[]byte(body),
444436
true)
445437

446-
if err != nil {
447-
return err
448-
}
449-
450-
return nil
438+
return err
451439
}
452440

453441
// DeleteStream
@@ -463,7 +451,7 @@ func (c *context) DeleteStreamSync(deleteStreamInput *v3io.DeleteStreamInput) er
463451
// get all shards in the stream
464452
response, err := c.GetContainerContentsSync(&v3io.GetContainerContentsInput{
465453
DataPlaneInput: deleteStreamInput.DataPlaneInput,
466-
Path: deleteStreamInput.Path,
454+
Path: deleteStreamInput.Path,
467455
})
468456

469457
if err != nil {
@@ -477,16 +465,16 @@ func (c *context) DeleteStreamSync(deleteStreamInput *v3io.DeleteStreamInput) er
477465
for _, content := range response.Output.(*v3io.GetContainerContentsOutput).Contents {
478466

479467
// TODO: handle error - stop deleting? return multiple errors?
480-
c.DeleteObjectSync(&v3io.DeleteObjectInput{
468+
c.DeleteObjectSync(&v3io.DeleteObjectInput{ // nolint: errcheck
481469
DataPlaneInput: deleteStreamInput.DataPlaneInput,
482-
Path: content.Key,
470+
Path: content.Key,
483471
})
484472
}
485473

486474
// delete the actual stream
487475
return c.DeleteObjectSync(&v3io.DeleteObjectInput{
488476
DataPlaneInput: deleteStreamInput.DataPlaneInput,
489-
Path: path.Dir(deleteStreamInput.Path) + "/",
477+
Path: path.Dir(deleteStreamInput.Path) + "/",
490478
})
491479
}
492480

@@ -586,7 +574,7 @@ func (c *context) PutRecordsSync(putRecordsInput *v3io.PutRecordsInput) (*v3io.R
586574
}
587575

588576
buffer.WriteString(`]}`)
589-
str := string(buffer.Bytes())
577+
str := buffer.String()
590578
fmt.Println(str)
591579

592580
response, err := c.sendRequest(&putRecordsInput.DataPlaneInput,
@@ -773,10 +761,8 @@ func (c *context) sendRequest(dataPlaneInput *v3io.DataPlaneInput,
773761
request.Header.Set("Authorization", dataPlaneInput.AuthenticationToken)
774762
}
775763

776-
if headers != nil {
777-
for headerName, headerValue := range headers {
778-
request.Header.Add(headerName, headerValue)
779-
}
764+
for headerName, headerValue := range headers {
765+
request.Header.Add(headerName, headerValue)
780766
}
781767

782768
c.logger.DebugWithCtx(dataPlaneInput.Ctx,

pkg/dataplane/http/headers.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v3iohttp
22

33
// function names
44
const (
5-
setObjectFunctionName = "ObjectSet"
65
putItemFunctionName = "PutItem"
76
updateItemFunctionName = "UpdateItem"
87
getItemFunctionName = "GetItem"
@@ -13,12 +12,6 @@ const (
1312
seekShardsFunctionName = "SeekShard"
1413
)
1514

16-
// headers for set object
17-
var setObjectHeaders = map[string]string{
18-
"Content-Type": "application/json",
19-
"X-v3io-function": setObjectFunctionName,
20-
}
21-
2215
// headers for put item
2316
var putItemHeaders = map[string]string{
2417
"Content-Type": "application/json",

pkg/dataplane/test/sync_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package test
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/suite"
5+
"testing"
6+
67
"github.com/v3io/v3io-go/pkg/dataplane"
78
"github.com/v3io/v3io-go/pkg/errors"
8-
"testing"
9+
10+
"github.com/stretchr/testify/suite"
911
)
1012

1113
type syncTestSuite struct {
@@ -21,7 +23,7 @@ type syncContainerTestSuite struct {
2123
}
2224

2325
func (suite *syncContainerTestSuite) TestGetContainers() {
24-
suite.T().Skip( )
26+
suite.T().Skip()
2527
suite.containerName = ""
2628

2729
getContainersInput := v3io.GetContainersInput{}

pkg/dataplane/test/test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package test
22

33
import (
4+
"os"
5+
6+
"github.com/v3io/v3io-go/pkg/dataplane"
7+
"github.com/v3io/v3io-go/pkg/dataplane/http"
8+
49
"github.com/nuclio/logger"
510
"github.com/nuclio/zap"
611
"github.com/stretchr/testify/suite"
7-
"github.com/v3io/v3io-go/pkg/dataplane"
8-
"github.com/v3io/v3io-go/pkg/dataplane/http"
9-
"os"
1012
)
1113

12-
type testSuite struct {
14+
type testSuite struct { // nolint: deadcode
1315
suite.Suite
1416
logger logger.Logger
1517
container v3io.Container

pkg/dataplane/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Content struct {
6565
XMLName xml.Name `xml:"Contents"`
6666
Key string `xml:"Key"`
6767
Size int `xml:"Size"`
68-
LastSequenceId int `xml:"LastSequenceId"`
68+
LastSequenceID int `xml:"LastSequenceId"`
6969
ETag string `xml:"ETag"`
7070
LastModified string `xml:"LastModified"`
7171
}
@@ -90,9 +90,9 @@ type GetContainersInput struct {
9090

9191
type GetContainersOutput struct {
9292
DataPlaneOutput
93-
XMLName xml.Name `xml:"ListAllMyBucketsResult"`
94-
Owner interface{} `xml:"Owner"`
95-
Results Containers `xml:"Buckets"`
93+
XMLName xml.Name `xml:"ListAllMyBucketsResult"`
94+
Owner interface{} `xml:"Owner"`
95+
Results Containers `xml:"Buckets"`
9696
}
9797

9898
type Containers struct {

0 commit comments

Comments
 (0)