diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..7f58edf74 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: go + +go: + - 1.10.x + + +before_install: + - make build-dev-deps + +script: + - make lint diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..8eab7d797 --- /dev/null +++ b/Jenkinsfile @@ -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 + */ + } +} diff --git a/Makefile b/Makefile index 14f68ad2e..161f77b3d 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ +.PHONY: test lint + lint: check-copyrights @echo "Running ${@}" - @gometalinter.v2 \ + @gometalinter \ --deadline=60s \ --disable-all \ --enable=golint \ --enable=goimports \ --enable=vet \ --enable=deadcode \ - --enable=gosimple \ + --enable=goconst \ --exclude=.*\.pb\.go \ + --exclude=.*_test.go \ ./... check-copyrights: @@ -22,6 +25,11 @@ proto: 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 gopkg.in/alecthomas/gometalinter.v2 - gometalinter.v2 --install + go get -u github.com/alecthomas/gometalinter + gometalinter --install --force + +test: + go test -v ./... diff --git a/cmd/storj-node/Dockerfile b/cmd/storj-node/Dockerfile deleted file mode 100644 index 394e90ebb..000000000 --- a/cmd/storj-node/Dockerfile +++ /dev/null @@ -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 diff --git a/examples/eestream/serve-collected/main.go b/examples/eestream/serve-collected/main.go index 1e008be41..dcbd8a86e 100644 --- a/examples/eestream/serve-collected/main.go +++ b/examples/eestream/serve-collected/main.go @@ -33,6 +33,7 @@ func main() { } } +// Main is the exported CLI executable function func Main() error { encKey := sha256.Sum256([]byte(*key)) fc, err := infectious.NewFEC(*rsk, *rsn) diff --git a/examples/eestream/serve-pieces/main.go b/examples/eestream/serve-pieces/main.go index e4903793c..2cb399104 100644 --- a/examples/eestream/serve-pieces/main.go +++ b/examples/eestream/serve-pieces/main.go @@ -27,6 +27,7 @@ func main() { } } +// Main is the exported CLI executable function func Main() error { pieces, err := ioutil.ReadDir(flag.Arg(0)) if err != nil { diff --git a/examples/eestream/serve/main.go b/examples/eestream/serve/main.go index f75aaed84..75c8a55b7 100644 --- a/examples/eestream/serve/main.go +++ b/examples/eestream/serve/main.go @@ -42,6 +42,7 @@ func main() { } } +// Main is the exported CLI executable function func Main() error { encKey := sha256.Sum256([]byte(*key)) fc, err := infectious.NewFEC(*rsk, *rsn) diff --git a/examples/eestream/store/main.go b/examples/eestream/store/main.go index aad406915..b241f617f 100644 --- a/examples/eestream/store/main.go +++ b/examples/eestream/store/main.go @@ -36,6 +36,7 @@ func main() { } } +// Main is the exported CLI executable function func Main() error { err := os.MkdirAll(flag.Arg(0), 0755) if err != nil { diff --git a/go.mod b/go.mod index 082880e77..2cd5726e0 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,29 @@ -module "storj.io/storj" +module storj.io/storj require ( - "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/zeebo/errs" v0.1.0 - "golang.org/x/crypto" v0.0.0-20180410182641-f70185d77e82 + github.com/fsnotify/fsnotify v1.4.7 + github.com/go-redis/redis v0.0.0-20180417061816-9ccc23344a52 + github.com/gogo/protobuf v1.0.0 + github.com/golang/protobuf v1.0.0 + 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 ) diff --git a/pkg/ranger/content.go b/pkg/ranger/content.go index 0c1b2138d..fbe8d5503 100644 --- a/pkg/ranger/content.go +++ b/pkg/ranger/content.go @@ -141,7 +141,7 @@ func ServeContent(w http.ResponseWriter, r *http.Request, name string, w.WriteHeader(code) - if r.Method != "HEAD" { + if r.Method != http.MethodHead { r := sendContent() defer r.Close() io.CopyN(w, r, sendSize) @@ -178,7 +178,7 @@ func checkPreconditions(w http.ResponseWriter, r *http.Request, } switch checkIfNoneMatch(w, r) { case condFalse: - if r.Method == "GET" || r.Method == "HEAD" { + if r.Method == http.MethodGet || r.Method == http.MethodHead { writeNotModified(w) return true, "" } @@ -284,7 +284,7 @@ func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) 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 } 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) ( rv condResult) { - if r.Method != "GET" && r.Method != "HEAD" { + if r.Method != http.MethodGet && r.Method != http.MethodHead { return condNone } ir := r.Header.Get("If-Range") @@ -419,6 +419,7 @@ func parseRange(s string, size int64) ([]httpRange, error) { if !strings.HasPrefix(s, b) { return nil, errors.New("invalid range") } + var ranges []httpRange noOverlap := false for _, ra := range strings.Split(s[len(b):], ",") { diff --git a/pkg/ranger/file.go b/pkg/ranger/file.go index e3f643897..3075939b6 100644 --- a/pkg/ranger/file.go +++ b/pkg/ranger/file.go @@ -8,10 +8,10 @@ import ( "os" ) -// FileHandleRanger returns a RangerCloser from a file handle. The -// RangerCloser's Close method will call fh.Close(). +// FileHandleRanger returns a RangeCloser from a file handle. The +// Closer's Close method will call fh.Close(). // 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() if err != nil { return nil, Error.Wrap(err) @@ -25,8 +25,8 @@ func FileHandleRanger(fh *os.File) (RangerCloser, error) { }, nil } -// FileRanger returns a RangerCloser from a path. -func FileRanger(path string) (RangerCloser, error) { +// FileRanger returns a RangeCloser from a path. +func FileRanger(path string) (RangeCloser, error) { fh, err := os.Open(path) if err != nil { return nil, err diff --git a/pkg/ranger/reader.go b/pkg/ranger/reader.go index ee79481ff..c36549b7f 100644 --- a/pkg/ranger/reader.go +++ b/pkg/ranger/reader.go @@ -19,15 +19,15 @@ type Ranger interface { Range(offset, length int64) io.ReadCloser } -// A RangerCloser is a Ranger that must be closed when finished -type RangerCloser interface { +// A RangeCloser is a Ranger that must be closed when finished +type RangeCloser interface { Ranger 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() -func NopCloser(r Ranger) RangerCloser { +func NopCloser(r Ranger) RangeCloser { return struct { Ranger io.Closer diff --git a/storage/redis/mock_client.go b/storage/redis/mock_client_test.go similarity index 85% rename from storage/redis/mock_client.go rename to storage/redis/mock_client_test.go index 1a042b652..3c9476078 100644 --- a/storage/redis/mock_client.go +++ b/storage/redis/mock_client_test.go @@ -15,7 +15,10 @@ type mockRedisClient struct { pingCalled int } +// ErrMissingKey is the error returned if a key is not in the mock store 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") func (m *mockRedisClient) Get(key string) ([]byte, error) {