tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
3.07k stars 479 forks source link

Code does not lint cleanly according to golangci-lint #417

Open ghost opened 4 years ago

ghost commented 4 years ago

Describe the bug

Code does not lint cleanly using golangci-lint. There are some small issues like missing formatting directives, errors not being checked, etc. See the end of the issue for a full report.

To Reproduce

  1. Install golangci-lint and associated default linters
  2. Run golangci-lint run ./... in the basedir of tusd.

Expected behavior

Code lints cleanly.

Setup details Please provide following details, if applicable to your situation:

Report

pkg/filelocker/filelocker.go:20:5: `defaultFilePerm` is unused (deadcode)
var defaultFilePerm = os.FileMode(0664)
    ^
cmd/tusd/cli/hooks/hooks.go:25:6: `hookDataStore` is unused (deadcode)
type hookDataStore struct {
     ^
pkg/handler/log.go:26:15: Error return value of `logger.Output` is not checked (errcheck)
    logger.Output(2, string(result))
                 ^
pkg/handler/unrouted_handler.go:398:21: Error return value of `lock.Unlock` is not checked (errcheck)
            defer lock.Unlock()
                             ^
pkg/handler/unrouted_handler.go:435:20: Error return value of `lock.Unlock` is not checked (errcheck)
        defer lock.Unlock()
                         ^
pkg/handler/unrouted_handler.go:512:20: Error return value of `lock.Unlock` is not checked (errcheck)
        defer lock.Unlock()
                         ^
pkg/handler/unrouted_handler.go:755:9: Error return value of `io.Copy` is not checked (errcheck)
    io.Copy(w, src)
           ^
pkg/handler/unrouted_handler.go:932:9: Error return value of `w.Write` is not checked (errcheck)
    w.Write(reason)
           ^
pkg/s3store/s3store.go:355:11: Error return value of `file.Seek` is not checked (errcheck)
    file.Seek(0, 0)
             ^
pkg/s3store/s3store.go:764:11: Error return value of `file.Seek` is not checked (errcheck)
    file.Seek(0, 0)
             ^
pkg/s3store/s3store.go:781:48: Error return value of `store.Service.AbortMultipartUploadWithContext` is not checked (errcheck)
        store.Service.AbortMultipartUploadWithContext(ctx, &s3.AbortMultipartUploadInput{
                                                     ^
pkg/s3store/s3store_test.go:818:15: Error return value of `writer.Write` is not checked (errcheck)
        writer.Write([]byte("1234567890ABCD"))
                    ^
pkg/s3store/s3store_test.go:819:24: Error return value of `writer.CloseWithError` is not checked (errcheck)
        writer.CloseWithError(io.ErrUnexpectedEOF)
                             ^
pkg/s3store/s3store_util_test.go:35:16: Error return value of `inputBody.Seek` is not checked (errcheck)
    inputBody.Seek(0, 0)
                  ^
pkg/s3store/s3store_util_test.go:41:20: Error return value of `m.expect.Body.Seek` is not checked (errcheck)
    m.expect.Body.Seek(0, 0)
                      ^
pkg/s3store/s3store_util_test.go:55:20: Error return value of `m.expect.Body.Seek` is not checked (errcheck)
    m.expect.Body.Seek(0, 0)
                      ^
pkg/s3store/s3store_util_test.go:82:16: Error return value of `inputBody.Seek` is not checked (errcheck)
    inputBody.Seek(0, 0)
                  ^
pkg/s3store/s3store_util_test.go:88:20: Error return value of `m.expect.Body.Seek` is not checked (errcheck)
    m.expect.Body.Seek(0, 0)
                      ^
pkg/handler/patch_test.go:522:16: Error return value of `writer.Write` is not checked (errcheck)
            writer.Write([]byte("first "))
                        ^
pkg/handler/patch_test.go:530:16: Error return value of `writer.Write` is not checked (errcheck)
            writer.Write([]byte("second "))
                        ^
cmd/tusd/cli/greeting.go:35:9: Error return value of `w.Write` is not checked (errcheck)
    w.Write([]byte(greeting))
           ^
pkg/gcsstore/gcsservice_test.go:267:10: ineffectual assignment to `err` (ineffassign)
    reader, err := service.ReadObject(ctx, GCSObjectParams{
            ^
cmd/tusd/cli/serve.go:135:16: printf: Fatalf call has arguments but no formatting directives (govet)
        stderr.Fatalf("error", err)
                     ^
pkg/handler/concat_test.go:16:80: SA4009: argument composer is overwritten before first use (staticcheck)
    SubTest(t, "ExtensionDiscovery", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
                                                                                  ^
pkg/handler/get_test.go:24:70: SA4009: argument composer is overwritten before first use (staticcheck)
    SubTest(t, "Download", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
                                                                        ^
pkg/handler/head_test.go:14:68: SA4009: argument composer is overwritten before first use (staticcheck)
    SubTest(t, "Status", func(t *testing.T, store *MockFullDataStore, composer *StoreComposer) {
                                                                      ^
pkg/handler/utils_test.go:38:6: type `FullLocker` is unused (unused)
pkg/handler/utils_test.go:24:6: type `FullDataStore` is unused (unused)
pkg/handler/utils_test.go:31:6: type `FullUpload` is unused (unused)
pkg/handler/utils_test.go:42:6: type `FullLock` is unused (unused)
Acconut commented 4 years ago

Thanks for reporting these! To me eye, there is nothing critical in here which needs immediate attention. Please open a PR to address them if you want to :)

Acconut commented 1 month ago

Current list:

internal/grouped_flags/grouped_flags_test.go:33:10: Error return value of `fs.Parse` is not checked (errcheck)
        fs.Parse()
                ^
pkg/handler/handler.go:48:12: Error return value of `w.Write` is not checked (errcheck)
                                w.Write([]byte(`method not allowed`))
                                       ^
pkg/handler/handler.go:69:12: Error return value of `w.Write` is not checked (errcheck)
                                w.Write([]byte(`method not allowed`))
                                       ^
pkg/handler/http.go:46:10: Error return value of `w.Write` is not checked (errcheck)
                w.Write([]byte(resp.Body))
                       ^
pkg/handler/unrouted_handler.go:428:21: Error return value of `lock.Unlock` is not checked (errcheck)
                        defer lock.Unlock()
                                         ^
pkg/handler/unrouted_handler.go:571:20: Error return value of `lock.Unlock` is not checked (errcheck)
                defer lock.Unlock()
                                 ^
pkg/handler/unrouted_handler.go:629:20: Error return value of `lock.Unlock` is not checked (errcheck)
                defer lock.Unlock()
                                 ^
pkg/handler/unrouted_handler.go:1041:9: Error return value of `io.Copy` is not checked (errcheck)
        io.Copy(w, src)
               ^
pkg/handler/patch_test.go:539:16: Error return value of `writer.Write` is not checked (errcheck)
                        writer.Write([]byte("hello"))
                                    ^
pkg/handler/patch_test.go:586:16: Error return value of `writer.Write` is not checked (errcheck)
                        writer.Write([]byte("first "))
                                    ^
pkg/handler/patch_test.go:594:16: Error return value of `writer.Write` is not checked (errcheck)
                        writer.Write([]byte("second "))
                                    ^
internal/e2e/e2e_test.go:63:17: Error return value of `server.Shutdown` is not checked (errcheck)
        server.Shutdown()
                       ^
internal/e2e/e2e_test.go:137:20: Error return value of `proxy.Delete` is not checked (errcheck)
        defer proxy.Delete()
                          ^
internal/e2e/e2e_test.go:141:16: Error return value of `proxy.AddToxic` is not checked (errcheck)
        proxy.AddToxic("", "bandwidth", "upstream", 1, toxiproxy.Attributes{
                      ^
internal/e2e/e2e_test.go:261:20: Error return value of `proxy.Delete` is not checked (errcheck)
        defer proxy.Delete()
                          ^
internal/e2e/e2e_test.go:266:16: Error return value of `proxy.AddToxic` is not checked (errcheck)
        proxy.AddToxic("", "bandwidth", "upstream", 1, toxiproxy.Attributes{
                      ^
internal/e2e/e2e_test.go:269:16: Error return value of `proxy.AddToxic` is not checked (errcheck)
        proxy.AddToxic("", "limit_data", "upstream", 1, toxiproxy.Attributes{
                      ^
internal/e2e/e2e_test.go:474:20: Error return value of `proxy.Delete` is not checked (errcheck)
        defer proxy.Delete()
                          ^
internal/e2e/e2e_unix_test.go:65:21: Error return value of `cmd.Process.Signal` is not checked (errcheck)
                cmd.Process.Signal(os.Interrupt)
                                  ^
pkg/s3store/s3store.go:602:11: Error return value of `io.Copy` is not checked (errcheck)
                        io.Copy(buf, res.Body)
                               ^
pkg/s3store/s3store.go:942:11: Error return value of `file.Seek` is not checked (errcheck)
        file.Seek(0, 0)
                 ^
pkg/s3store/s3store.go:959:37: Error return value of `store.Service.AbortMultipartUpload` is not checked (errcheck)
                store.Service.AbortMultipartUpload(ctx, &s3.AbortMultipartUploadInput{
                                                  ^
pkg/s3store/s3store_part_producer.go:54:24: Error return value is not checked (errcheck)
                fileChunk.closeReader()
                                     ^
pkg/s3store/s3store_part_producer.go:112:12: Error return value of `file.Seek` is not checked (errcheck)
                file.Seek(0, 0)
                         ^
pkg/s3store/s3store_part_producer_test.go:52:20: Error return value is not checked (errcheck)
                chunk.closeReader()
                                 ^
pkg/s3store/s3store_util_test.go:35:16: Error return value of `inputBody.Seek` is not checked (errcheck)
        inputBody.Seek(0, 0)
                      ^
pkg/s3store/s3store_util_test.go:41:17: Error return value of `expectBody.Seek` is not checked (errcheck)
        expectBody.Seek(0, 0)
                       ^
pkg/s3store/s3store_util_test.go:55:36: Error return value of `(io.Seeker).Seek` is not checked (errcheck)
        m.expect.Body.(io.ReadSeeker).Seek(0, 0)
                                          ^
pkg/s3store/s3store_util_test.go:82:16: Error return value of `inputBody.Seek` is not checked (errcheck)
        inputBody.Seek(0, 0)
                      ^
pkg/s3store/s3store_util_test.go:88:17: Error return value of `expectBody.Seek` is not checked (errcheck)
        expectBody.Seek(0, 0)
                       ^
pkg/s3store/s3store_util_test.go:102:36: Error return value of `(io.Seeker).Seek` is not checked (errcheck)
        m.expect.Body.(io.ReadSeeker).Seek(0, 0)
                                          ^
cmd/tusd/cli/flags.go:194:10: Error return value of `fs.Parse` is not checked (errcheck)
        fs.Parse()
                ^
cmd/tusd/cli/composer.go:130:18: printf: non-constant format string in call to (*log.Logger).Fatalf (govet)
                        stderr.Fatalf(err.Error())
                                      ^
pkg/hooks/grpc/grpc.go:34:15: SA1019: grpc.Dial is deprecated: use NewClient instead.  Will be supported throughout 1.x. (staticcheck)
        conn, err := grpc.Dial(g.Endpoint, grpcOpts...)