Merge pull request #20 from coyle/clean-lint

Clean lint!
This commit is contained in:
Natalie Villasana 2018-05-07 14:14:40 -04:00 committed by GitHub
commit c73a4f9d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 121 additions and 34 deletions

11
.travis.yml Normal file
View File

@ -0,0 +1,11 @@
language: go
go:
- 1.10.x
before_install:
- make build-dev-deps
script:
- make lint

51
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,51 @@
node('node') {
// Install the desired Go version
def root = tool name: 'Go 1.10', type: 'go'
// Export environment variables pointing to the directory where Go was installed
withEnv(["GOROOT=${root}", "PATH+GO=${root}/bin", "PATH=$PATH:${root}/bin"]) {
sh 'go version'
}
try {
stage 'Checkout'
checkout scm
stage 'Test'
sh """#!/bin/bash -e
echo $root
echo "path="
echo $PATH
make build-dev-deps lint
"""
stage 'Build Docker'
echo 'Build'
stage 'Deploy'
echo 'Deploy'
stage 'Cleanup'
echo 'prune and cleanup'
}
catch (err) {
currentBuild.result = "FAILURE"
/*
mail body: "project build error is here: ${env.BUILD_URL}" ,
from: 'build@storj.io',
replyTo: 'build@storj.io',
subject: 'project build failed',
to: "${env.CHANGE_AUTHOR_EMAIL}"
throw err
*/
}
}

View File

@ -1,14 +1,17 @@
.PHONY: test lint
lint: check-copyrights lint: check-copyrights
@echo "Running ${@}" @echo "Running ${@}"
@gometalinter.v2 \ @gometalinter \
--deadline=60s \ --deadline=60s \
--disable-all \ --disable-all \
--enable=golint \ --enable=golint \
--enable=goimports \ --enable=goimports \
--enable=vet \ --enable=vet \
--enable=deadcode \ --enable=deadcode \
--enable=gosimple \ --enable=goconst \
--exclude=.*\.pb\.go \ --exclude=.*\.pb\.go \
--exclude=.*_test.go \
./... ./...
check-copyrights: check-copyrights:
@ -22,6 +25,11 @@ proto:
build-dev-deps: build-dev-deps:
go get -u golang.org/x/vgo
vgo install ./...
go get -u github.com/golang/protobuf/protoc-gen-go go get -u github.com/golang/protobuf/protoc-gen-go
go get -u gopkg.in/alecthomas/gometalinter.v2 go get -u github.com/alecthomas/gometalinter
gometalinter.v2 --install gometalinter --install --force
test:
go test -v ./...

View File

@ -1,11 +0,0 @@
# build
FROM golang:alpine AS build-env
ADD . /go/src/research/lang/storj-node-go/
RUN cd /go/src/research/lang/storj-node-go/ && go build -o main
# final stage
FROM alpine
WORKDIR /app
COPY --from=build-env /go/src/research/lang/storj-node-go/main /app/
ENTRYPOINT ./main

View File

@ -33,6 +33,7 @@ func main() {
} }
} }
// Main is the exported CLI executable function
func Main() error { func Main() error {
encKey := sha256.Sum256([]byte(*key)) encKey := sha256.Sum256([]byte(*key))
fc, err := infectious.NewFEC(*rsk, *rsn) fc, err := infectious.NewFEC(*rsk, *rsn)

View File

@ -27,6 +27,7 @@ func main() {
} }
} }
// Main is the exported CLI executable function
func Main() error { func Main() error {
pieces, err := ioutil.ReadDir(flag.Arg(0)) pieces, err := ioutil.ReadDir(flag.Arg(0))
if err != nil { if err != nil {

View File

@ -42,6 +42,7 @@ func main() {
} }
} }
// Main is the exported CLI executable function
func Main() error { func Main() error {
encKey := sha256.Sum256([]byte(*key)) encKey := sha256.Sum256([]byte(*key))
fc, err := infectious.NewFEC(*rsk, *rsn) fc, err := infectious.NewFEC(*rsk, *rsn)

View File

@ -36,6 +36,7 @@ func main() {
} }
} }
// Main is the exported CLI executable function
func Main() error { func Main() error {
err := os.MkdirAll(flag.Arg(0), 0755) err := os.MkdirAll(flag.Arg(0), 0755)
if err != nil { if err != nil {

32
go.mod
View File

@ -1,9 +1,29 @@
module "storj.io/storj" module storj.io/storj
require ( require (
"github.com/spf13/viper" v1.0.2 github.com/fsnotify/fsnotify v1.4.7
"github.com/tyler-smith/go-bip39" v0.0.0-20160629163856-8e7a99b3e716 github.com/go-redis/redis v0.0.0-20180417061816-9ccc23344a52
"github.com/urfave/cli" v1.20.0 github.com/gogo/protobuf v1.0.0
"github.com/zeebo/errs" v0.1.0 github.com/golang/protobuf v1.0.0
"golang.org/x/crypto" v0.0.0-20180410182641-f70185d77e82 github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/magiconair/properties v1.7.6
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238
github.com/pelletier/go-toml v1.1.0
github.com/spacemonkeygo/errors v0.0.0-20171212215202-9064522e9fd1
github.com/spf13/afero v1.1.0
github.com/spf13/cast v1.2.0
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec
github.com/spf13/pflag v1.0.1
github.com/spf13/viper v1.0.2
github.com/tyler-smith/go-bip39 v0.0.0-20160629163856-8e7a99b3e716
github.com/urfave/cli v1.20.0
github.com/vivint/infectious v0.0.0-20180418194855-57d6abddc3d4
github.com/zeebo/errs v0.1.0
golang.org/x/crypto v0.0.0-20180410182641-f70185d77e82
golang.org/x/net v0.0.0-20180420171651-5f9ae10d9af5
golang.org/x/sys v0.0.0-20180430173509-4adea008a5e5
golang.org/x/text v0.3.0
google.golang.org/genproto v0.0.0-20180427144745-86e600f69ee4
google.golang.org/grpc v1.11.3
gopkg.in/yaml.v2 v2.2.1
) )

View File

@ -141,7 +141,7 @@ func ServeContent(w http.ResponseWriter, r *http.Request, name string,
w.WriteHeader(code) w.WriteHeader(code)
if r.Method != "HEAD" { if r.Method != http.MethodHead {
r := sendContent() r := sendContent()
defer r.Close() defer r.Close()
io.CopyN(w, r, sendSize) io.CopyN(w, r, sendSize)
@ -178,7 +178,7 @@ func checkPreconditions(w http.ResponseWriter, r *http.Request,
} }
switch checkIfNoneMatch(w, r) { switch checkIfNoneMatch(w, r) {
case condFalse: case condFalse:
if r.Method == "GET" || r.Method == "HEAD" { if r.Method == http.MethodGet || r.Method == http.MethodHead {
writeNotModified(w) writeNotModified(w)
return true, "" return true, ""
} }
@ -284,7 +284,7 @@ func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult {
} }
func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult { func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
if r.Method != "GET" && r.Method != "HEAD" { if r.Method != http.MethodGet && r.Method != http.MethodHead {
return condNone return condNone
} }
ims := r.Header.Get("If-Modified-Since") ims := r.Header.Get("If-Modified-Since")
@ -305,7 +305,7 @@ func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
func checkIfRange(w http.ResponseWriter, r *http.Request, modtime time.Time) ( func checkIfRange(w http.ResponseWriter, r *http.Request, modtime time.Time) (
rv condResult) { rv condResult) {
if r.Method != "GET" && r.Method != "HEAD" { if r.Method != http.MethodGet && r.Method != http.MethodHead {
return condNone return condNone
} }
ir := r.Header.Get("If-Range") ir := r.Header.Get("If-Range")
@ -419,6 +419,7 @@ func parseRange(s string, size int64) ([]httpRange, error) {
if !strings.HasPrefix(s, b) { if !strings.HasPrefix(s, b) {
return nil, errors.New("invalid range") return nil, errors.New("invalid range")
} }
var ranges []httpRange var ranges []httpRange
noOverlap := false noOverlap := false
for _, ra := range strings.Split(s[len(b):], ",") { for _, ra := range strings.Split(s[len(b):], ",") {

View File

@ -8,10 +8,10 @@ import (
"os" "os"
) )
// FileHandleRanger returns a RangerCloser from a file handle. The // FileHandleRanger returns a RangeCloser from a file handle. The
// RangerCloser's Close method will call fh.Close(). // Closer's Close method will call fh.Close().
// Footgun: If FileHandleRanger fails, fh.Close will not have been called. // Footgun: If FileHandleRanger fails, fh.Close will not have been called.
func FileHandleRanger(fh *os.File) (RangerCloser, error) { func FileHandleRanger(fh *os.File) (RangeCloser, error) {
stat, err := fh.Stat() stat, err := fh.Stat()
if err != nil { if err != nil {
return nil, Error.Wrap(err) return nil, Error.Wrap(err)
@ -25,8 +25,8 @@ func FileHandleRanger(fh *os.File) (RangerCloser, error) {
}, nil }, nil
} }
// FileRanger returns a RangerCloser from a path. // FileRanger returns a RangeCloser from a path.
func FileRanger(path string) (RangerCloser, error) { func FileRanger(path string) (RangeCloser, error) {
fh, err := os.Open(path) fh, err := os.Open(path)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -19,15 +19,15 @@ type Ranger interface {
Range(offset, length int64) io.ReadCloser Range(offset, length int64) io.ReadCloser
} }
// A RangerCloser is a Ranger that must be closed when finished // A RangeCloser is a Ranger that must be closed when finished
type RangerCloser interface { type RangeCloser interface {
Ranger Ranger
io.Closer io.Closer
} }
// NopCloser makes an existing Ranger function as a RangerCloser // NopCloser makes an existing Ranger function as a RangeCloser
// with a no-op for Close() // with a no-op for Close()
func NopCloser(r Ranger) RangerCloser { func NopCloser(r Ranger) RangeCloser {
return struct { return struct {
Ranger Ranger
io.Closer io.Closer

View File

@ -15,7 +15,10 @@ type mockRedisClient struct {
pingCalled int pingCalled int
} }
// ErrMissingKey is the error returned if a key is not in the mock store
var ErrMissingKey = errors.New("missing") var ErrMissingKey = errors.New("missing")
// ErrForced is the error returned when the forced error flag is passed to mock an error
var ErrForced = errors.New("error forced by using 'error' key in mock") var ErrForced = errors.New("error forced by using 'error' key in mock")
func (m *mockRedisClient) Get(key string) ([]byte, error) { func (m *mockRedisClient) Get(key string) ([]byte, error) {