diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000000..5ab82a70564 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# Global owners + +* @batazor diff --git a/.golangci.yml b/.golangci.yml index e69de29bb2d..7f3d1698eb8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -0,0 +1,304 @@ +# This file contains all available configuration options +# with their default values. + +# options for analysis running +run: + # default concurrency is a available CPU number + concurrency: 4 + + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 5m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + + # list of build tags, all linters use it. Default is empty list. + # build-tags: + # - mytag + + # which dirs to skip: issues from them won't be reported; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but default dirs are skipped independently + # from this option's value (see skip-dirs-use-default). + # skip-dirs: + # - src/external_libs + # - autogenerated_by_my_lib + + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. + # skip-files: + # - ".*\\.my\\.go$" + # - lib/bad.go + + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # modules-download-mode: readonly|release|vendor + + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: colored-line-number + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + + +# all available settings of specific linters +linters-settings: + errcheck: + # report about not checking of errors in type assetions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: true + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: true + + # [deprecated] comma-separated list of pairs of the form pkg:regex + # the regex is used to ignore names within pkg. (default "fmt:.*"). + # see https://github.com/kisielk/errcheck#the-deprecated-method for details + # ignore: fmt:.*,io/ioutil:^Read.* + + # path to a file containing a list of functions to exclude from checking + # see https://github.com/kisielk/errcheck#excluding-functions for details + # exclude: /path/to/file.txt + + funlen: + lines: 60 + statements: 40 + + govet: + # report about shadowed variables + check-shadowing: true + + # settings per analyzer + settings: + printf: # analyzer name, run `go tool vet help` to see all analyzers + funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + + # enable or disable analyzers by name + # enable: + # - atomicalign + enable-all: true + # disable: + # - shadow + disable-all: false + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.8 + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: github.com/org/project + gocyclo: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + gocognit: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + goconst: + # minimal length of string constant, 3 by default + min-len: 3 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 3 + depguard: + list-type: blacklist + include-go-root: false + packages: + - github.com/sirupsen/logrus + packages-with-error-messages: + # specify an error message to output when a blacklisted package is used + github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + ignore-words: + - someword + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 120 + # tab width in spaces. Default to 1. + tab-width: 1 + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: true + unparam: + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: true + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 30 + prealloc: + # XXX: we don't recommend using this linter before doing performance profiling. + # For most programs usage of prealloc will be a premature optimization. + + # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. + # True by default. + simple: true + range-loops: true # Report preallocation suggestions on range loops, true by default + for-loops: true # Report preallocation suggestions on for loops, false by default + gocritic: + # Which checks should be enabled; can't be combined with 'disabled-checks'; + # See https://go-critic.github.io/overview#checks-overview + # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` + # By default list of stable checks is used. + # enabled-checks: + # - rangeValCopy + + # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + disabled-checks: + - regexpMust + + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - performance + + settings: # settings passed to gocritic + captLocal: # must be valid enabled check name + paramsOnly: true + rangeValCopy: + sizeThreshold: 32 + godox: + # report any comments starting with keywords, this is useful for TODO or FIXME comments that + # might be left in the code accidentally and should be resolved before merging + keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting + - NOTE + - OPTIMIZE # marks code that should be optimized before merging + - HACK # marks hack-arounds that should be removed before merging + dogsled: + # checks assignments with too many blank identifiers; default is 2 + max-blank-identifiers: 2 + + whitespace: + multi-if: true # Enforces newlines (or comments) after every multi-line if statement + multi-func: true # Enforces newlines (or comments) after every multi-line function signature + wsl: + # If true append is only allowed to be cuddled if appending value is + # matching variables, fields or types on line above. Default is true. + strict-append: true + # Allow calls and assignments to be cuddled as long as the lines have any + # matching variables, fields or types. Default is true. + allow-assign-and-call: true + # Allow multiline assignments to be cuddled. Default is true. + allow-multiline-assign: true + # Allow case blocks to end with a whitespace. + allow-case-traling-whitespace: true + # Allow declarations (var) to be cuddled. + allow-cuddle-declarations: true + +linters: + enable: + - megacheck + - govet + # disable: + # - maligned + # - prealloc + disable-all: false + presets: + - bugs + - unused + fast: false + + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + # exclude: + # - abcdef + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via "nolint" comments. + - path: internal/hmac/ + text: "weak cryptographic primitive" + linters: + - gosec + + # Exclude some staticcheck messages + - linters: + - staticcheck + text: "SA9003:" + + # Exclude lll issues for long lines with go:generate + - linters: + - lll + source: "^//go:generate " + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: false + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing + # large codebase. It's not practical to fix all existing issues at the moment + # of integration: much better don't allow issues in new code. + # Default is false. + new: false + + # Show only new issues created after git revision `REV` + # new-from-rev: REV + + # Show only new issues created in git patch with set file path. + # new-from-patch: path/to/patch/file diff --git a/.travis.yml b/.travis.yml index bbb58978095..de7a747027e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ language: go before_install: - make dep - - go install github.com/golangci/golangci-lint/cmd/golangci-lint # Force-enable Go modules. Also force go to use the code in vendor/ # These will both be unnecessary when Go 1.14 lands. @@ -16,12 +15,15 @@ before_install: go: - 1.13.x +#go_import_path: + cache: directories: - $GOPATH/pkg/mod # Only clone the most recent commit. git: + submodules: false depth: 1 # Skip the install step. Don't `go get` dependencies. Only build with the code @@ -32,12 +34,20 @@ install: true notifications: email: false -# script always runs to completion (set +e). If we have linter issues AND a -# failing test, we want to see both. Configure golangci-lint with a -# .golangci.yml file at the top level of your repo. -script: - - make golint - - make test - -after_success: - - bash <(curl -s https://codecov.io/bash) +jobs: + include: + - os: linux + name: golint + # script always runs to completion (set +e). If we have linter issues AND a + # failing test, we want to see both. Configure golangci-lint with a + # .golangci.yml file at the top level of your repo. + script: + - make golint + - os: linux + name: test + before_install: + - go install github.com/golangci/golangci-lint/cmd/golangci-lint + script: + - make test + after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/cmd/shortlink/shortlink.go b/cmd/shortlink/shortlink.go index 80b46436326..2a604db4c1d 100644 --- a/cmd/shortlink/shortlink.go +++ b/cmd/shortlink/shortlink.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "github.com/batazor/shortlink/pkg/api" "github.com/batazor/shortlink/pkg/api/graphql" "github.com/batazor/shortlink/pkg/api/grpc-web" @@ -13,9 +14,16 @@ import ( func main() { // Logger - logger, _ := zap.NewProduction() + logger, err := zap.NewProduction() + if err != nil { + panic(err) + } defer func() { - _ = logger.Sync() // flushes buffer, if any + // flushes buffer, if any + if error := logger.Sync(); error != nil { + // TODO: use logger + fmt.Println(error.Error()) + } }() // Add context @@ -29,7 +37,10 @@ func main() { // Add Tracer tracer, closer, err := traicing.Init() defer func() { - closer.Close() + // TODO: use logger + if error := closer.Close(); error != nil { + fmt.Println(error.Error()) + } }() if err != nil { logger.Error(err.Error()) diff --git a/pkg/api/graphql/graphql.go b/pkg/api/graphql/graphql.go index c3227e2989b..b6107fa66b5 100644 --- a/pkg/api/graphql/graphql.go +++ b/pkg/api/graphql/graphql.go @@ -12,17 +12,17 @@ import ( ) // API ... -type API struct { +type API struct { // nolint unused store store.DB ctx context.Context } // GetHandler ... -func (api *API) GetHandler() (*relay.Handler, error) { +func (api *API) GetHandler() *relay.Handler { s := graphql.MustParseSchema(schema.GetRootSchema(), &resolver.Resolver{Store: api.store}) handler := relay.Handler{Schema: s} - return &handler, nil + return &handler } // Run ... @@ -35,13 +35,10 @@ func (api *API) Run(ctx context.Context) error { log := logger.GetLogger(ctx) log.Info("Run GraphQL API") - handler, err := api.GetHandler() - if err != nil { - return err - } + handler := api.GetHandler() http.Handle("/api/query", handler) - err = http.ListenAndServe(":7070", nil) + err := http.ListenAndServe(":7070", nil) return err } diff --git a/pkg/api/graphql/resolver/link_mutation.go b/pkg/api/graphql/resolver/link_mutation.go index 121440a1bb5..2d292657c16 100644 --- a/pkg/api/graphql/resolver/link_mutation.go +++ b/pkg/api/graphql/resolver/link_mutation.go @@ -6,7 +6,7 @@ import ( ) // CreateLink ... -func (r *Resolver) CreateLink(ctx context.Context, args *struct { +func (r *Resolver) CreateLink(ctx context.Context, args *struct { //nolint unused URL *string Hash *string Describe *string @@ -22,7 +22,7 @@ func (r *Resolver) CreateLink(ctx context.Context, args *struct { } // UpdateLink ... -func (*Resolver) UpdateLink(ctx context.Context, args *struct { +func (*Resolver) UpdateLink(ctx context.Context, args *struct { //nolint unused URL *string Hash *string Describe *string @@ -31,9 +31,11 @@ func (*Resolver) UpdateLink(ctx context.Context, args *struct { } // DeleteLink ... -func (r *Resolver) DeleteLink(ctx context.Context, args *struct { +func (r *Resolver) DeleteLink(ctx context.Context, args *struct { //nolint unused Hash *string -}) (*bool, error) { - error := r.Store.Delete(*args.Hash) - return nil, error +}) (bool, error) { + if error := r.Store.Delete(*args.Hash); error != nil { + return false, error + } + return true, nil } diff --git a/pkg/api/graphql/resolver/link_resolver.go b/pkg/api/graphql/resolver/link_resolver.go index d33561609da..acb3e1fab05 100644 --- a/pkg/api/graphql/resolver/link_resolver.go +++ b/pkg/api/graphql/resolver/link_resolver.go @@ -5,7 +5,7 @@ import ( ) // Link ... -func (r *Resolver) Link(ctx context.Context, args struct { +func (r *Resolver) Link(ctx context.Context, args struct { //nolint unparam Hash *string }) (*LinkResolver, error) { response, err := r.Store.Get(*args.Hash) @@ -15,6 +15,6 @@ func (r *Resolver) Link(ctx context.Context, args struct { } // Links ... -func (r *Resolver) Links() (*[]*LinkResolver, error) { +func (r *Resolver) Links() (*[]*LinkResolver, error) { // nolint unused return &[]*LinkResolver{}, nil } diff --git a/pkg/api/graphql/resolver/resolver.go b/pkg/api/graphql/resolver/resolver.go index 6c333a6df93..fad61b025bd 100644 --- a/pkg/api/graphql/resolver/resolver.go +++ b/pkg/api/graphql/resolver/resolver.go @@ -3,6 +3,6 @@ package resolver import "github.com/batazor/shortlink/pkg/internal/store" // Resolver ... -type Resolver struct { +type Resolver struct { //nolint unused Store store.DB } diff --git a/pkg/api/graphql/schema/schema.go b/pkg/api/graphql/schema/schema.go index 8ee34c4bfed..2ee8f5fec9c 100644 --- a/pkg/api/graphql/schema/schema.go +++ b/pkg/api/graphql/schema/schema.go @@ -12,15 +12,19 @@ import "bytes" // // If this method complains about not finding functions AssetNames() or MustAsset(), // run `go generate` against this package to generate the functions. -func GetRootSchema() string { +func GetRootSchema() string { // nolint unused buf := bytes.Buffer{} for _, name := range AssetNames() { b := MustAsset(name) - buf.Write(b) + if _, err := buf.Write(b); err != nil { + panic(err) + } // Add a newline if the file does not end in a newline. if len(b) > 0 && b[len(b)-1] != '\n' { - buf.WriteByte('\n') + if err := buf.WriteByte('\n'); err != nil { + panic(err) + } } } diff --git a/pkg/api/http-chi/http.go b/pkg/api/http-chi/http.go index dfa30445456..e0ae2a9f1a1 100644 --- a/pkg/api/http-chi/http.go +++ b/pkg/api/http-chi/http.go @@ -30,7 +30,7 @@ func (api *API) Add(w http.ResponseWriter, r *http.Request) { err := decoder.Decode(&request) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } @@ -42,19 +42,19 @@ func (api *API) Add(w http.ResponseWriter, r *http.Request) { newLink, err = api.store.Add(*newLink) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } res, err := json.Marshal(newLink) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } w.WriteHeader(http.StatusCreated) - _, _ = w.Write(res) + _, _ = w.Write(res) // nolint errcheck } // Get ... @@ -72,24 +72,24 @@ func (api *API) Get(w http.ResponseWriter, r *http.Request) { var errorLink *link.NotFoundError if errors.As(err, &errorLink) { w.WriteHeader(http.StatusNotFound) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } res, err := json.Marshal(response) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } w.WriteHeader(http.StatusOK) - _, _ = w.Write(res) + _, _ = w.Write(res) // nolint errcheck } // Delete ... @@ -99,11 +99,11 @@ func (api *API) Delete(w http.ResponseWriter, r *http.Request) { // Parse request b, err := ioutil.ReadAll(r.Body) defer func() { - _ = r.Body.Close() + _ = r.Body.Close() // nolint errcheck }() if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } @@ -111,17 +111,17 @@ func (api *API) Delete(w http.ResponseWriter, r *http.Request) { err = json.Unmarshal(b, &request) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } err = api.store.Delete(request.Hash) if err != nil { w.WriteHeader(http.StatusBadRequest) - _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) + _, _ = w.Write([]byte(`{"error": "` + err.Error() + `"}`)) // nolint errcheck return } w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{}`)) + _, _ = w.Write([]byte(`{}`)) // nolint errcheck } diff --git a/pkg/api/http-chi/middleware/logger.go b/pkg/api/http-chi/middleware/logger.go index 170d3d50964..e60862d6669 100644 --- a/pkg/api/http-chi/middleware/logger.go +++ b/pkg/api/http-chi/middleware/logger.go @@ -10,12 +10,12 @@ import ( "go.uber.org/zap" ) -type chilogger struct { +type chilogger struct { // nolint unused logZ *zap.Logger } // Logger returns a new Zap Middleware handler. -func Logger(logger *zap.Logger) func(next http.Handler) http.Handler { +func Logger(logger *zap.Logger) func(next http.Handler) http.Handler { // nolint unused return chilogger{ logZ: logger, }.middleware @@ -26,7 +26,7 @@ func (c chilogger) middleware(next http.Handler) http.Handler { start := time.Now() var requestID string if reqID := r.Context().Value(middleware.RequestIDKey); reqID != nil { - requestID = reqID.(string) + requestID = reqID.(string) // nolint errcheck } ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) next.ServeHTTP(ww, r) diff --git a/pkg/api/http-chi/server.go b/pkg/api/http-chi/server.go index 52f645dd3c2..ff03b712371 100644 --- a/pkg/api/http-chi/server.go +++ b/pkg/api/http-chi/server.go @@ -63,7 +63,7 @@ func (api *API) Run(ctx context.Context) error { } // NotFoundHandler - default handler for don't existing routers -func NotFoundHandler(w http.ResponseWriter, r *http.Request) { +func NotFoundHandler(w http.ResponseWriter, r *http.Request) { // nolint unused w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusNotFound) } diff --git a/pkg/api/http-chi/types.go b/pkg/api/http-chi/types.go index ef85527bed1..ac985e6cfda 100644 --- a/pkg/api/http-chi/types.go +++ b/pkg/api/http-chi/types.go @@ -6,24 +6,24 @@ import ( ) // API ... -type API struct { +type API struct { // nolint unused store store.DB ctx context.Context } // addRequest ... -type addRequest struct { +type addRequest struct { // nolint unused URL string Describe string } // getRequest ... -type getRequest struct { +type getRequest struct { // nolint unused Hash string Describe string } // deleteRequest ... -type deleteRequest struct { +type deleteRequest struct { // nolint unused Hash string } diff --git a/pkg/internal/store/badger.go b/pkg/internal/store/badger.go index 01c2b580eb8..4b5b73f77d8 100644 --- a/pkg/internal/store/badger.go +++ b/pkg/internal/store/badger.go @@ -80,8 +80,7 @@ func (b *BadgerLinkList) Add(data link.Link) (*link.Link, error) { } err = b.client.Update(func(txn *badger.Txn) error { - err := txn.Set([]byte(data.Hash), payload) - return err + return txn.Set([]byte(data.Hash), payload) }) if err != nil { return nil, err diff --git a/pkg/internal/store/dgraph.go b/pkg/internal/store/dgraph.go index e5a8dd2ff94..1e382141e09 100644 --- a/pkg/internal/store/dgraph.go +++ b/pkg/internal/store/dgraph.go @@ -50,7 +50,10 @@ func (dg *DGraphLinkList) get(id string) (*DGraphLinkResponse, error) { ctx := context.Background() txn := dg.client.NewTxn() defer func() { - _ = txn.Discard(ctx) + if err := txn.Discard(ctx); err != nil { + // TODO: use logger + fmt.Println(err.Error()) + } }() q := ` @@ -82,7 +85,10 @@ func (dg *DGraphLinkList) Get(id string) (*link.Link, error) { ctx := context.Background() txn := dg.client.NewTxn() defer func() { - _ = txn.Discard(ctx) + if err := txn.Discard(ctx); err != nil { + // TODO: use logger + fmt.Println(err.Error()) + } }() response, err := dg.get(id) @@ -109,7 +115,10 @@ func (dg *DGraphLinkList) Add(data link.Link) (*link.Link, error) { ctx := context.Background() txn := dg.client.NewTxn() defer func() { - _ = txn.Discard(ctx) + if err := txn.Discard(ctx); err != nil { + // TODO: use logger + fmt.Println(err.Error()) + } }() item := DGraphLink{ @@ -148,7 +157,10 @@ func (dg *DGraphLinkList) Delete(id string) error { ctx := context.Background() txn := dg.client.NewTxn() defer func() { - _ = txn.Discard(ctx) + if err := txn.Discard(ctx); err != nil { + // TODO: use logger + fmt.Println(err.Error()) + } }() links, err := dg.get(id) @@ -180,7 +192,10 @@ func (dg *DGraphLinkList) migration() error { ctx := context.Background() txn := dg.client.NewTxn() defer func() { - _ = txn.Discard(ctx) + if err := txn.Discard(ctx); err != nil { + // TODO: use logger + fmt.Println(err.Error()) + } }() op := &api.Operation{ diff --git a/pkg/internal/store/store_test.go b/pkg/internal/store/store_test.go index 1a5236e20b4..35d54d0ee33 100644 --- a/pkg/internal/store/store_test.go +++ b/pkg/internal/store/store_test.go @@ -5,7 +5,8 @@ import ( "testing" ) -func TestLink(t *testing.T) { +// TestLink ... +func TestLink(t *testing.T) { //nolint unused var st Store s := st.Use() diff --git a/pkg/link/errors.go b/pkg/link/errors.go index 13374a10826..b25e92abe70 100644 --- a/pkg/link/errors.go +++ b/pkg/link/errors.go @@ -4,7 +4,7 @@ import ( "fmt" ) -type NotFoundError struct { +type NotFoundError struct { // nolint unused Link Link Err error } diff --git a/pkg/link/link.go b/pkg/link/link.go index 0ebc56cf28a..77a208b3280 100644 --- a/pkg/link/link.go +++ b/pkg/link/link.go @@ -6,14 +6,14 @@ import ( "encoding/hex" ) -func NewURL(link string) (Link, error) { +func NewURL(link string) (Link, error) { // nolint unparam newLink := Link{URL: link} return newLink, nil } -func (l *Link) CreateHash(str, secret []byte) string { +func (l *Link) CreateHash(str, secret []byte) string { // nolint unused h := hmac.New(sha512.New, secret) - _, _ = h.Write(str) + _, _ = h.Write(str) // nolint errcheck sha := hex.EncodeToString(h.Sum(nil)) return sha } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 4d5400215fe..a808b3da9af 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -6,11 +6,11 @@ import ( ) // WithLogger set logger -func WithLogger(ctx context.Context, logger zap.Logger) context.Context { +func WithLogger(ctx context.Context, logger zap.Logger) context.Context { //nolint unused return context.WithValue(ctx, keyLogger, logger) } // GetLogger return logger -func GetLogger(ctx context.Context) zap.Logger { +func GetLogger(ctx context.Context) zap.Logger { //nolint unused return ctx.Value(keyLogger).(zap.Logger) } diff --git a/pkg/logger/types.go b/pkg/logger/types.go index 49810635592..91de93c0c8b 100644 --- a/pkg/logger/types.go +++ b/pkg/logger/types.go @@ -7,10 +7,10 @@ const ( ) //Fields Type to pass when we want to call WithFields for structured logging -type Fields map[string]interface{} +type Fields map[string]interface{} //nolint unused //Logger is our contract for the logger -type Logger interface { +type Logger interface { //nolint unused Info(msg string, fields Fields) Warn(msg string, fields Fields) diff --git a/pkg/traicing/traicing.go b/pkg/traicing/traicing.go index 0447c9e30e6..2d1f39a5150 100644 --- a/pkg/traicing/traicing.go +++ b/pkg/traicing/traicing.go @@ -9,7 +9,7 @@ import ( ) // Init returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout. -func Init() (opentracing.Tracer, io.Closer, error) { +func Init() (opentracing.Tracer, io.Closer, error) { // nolint unused cfg := &config.Configuration{ ServiceName: "ShortLink", RPCMetrics: true, @@ -30,11 +30,11 @@ func Init() (opentracing.Tracer, io.Closer, error) { } // WithTraicer set logger -func WithTraicer(ctx context.Context, traicer opentracing.Tracer) context.Context { +func WithTraicer(ctx context.Context, traicer opentracing.Tracer) context.Context { // nolint unused return context.WithValue(ctx, keyTraicer, traicer) } // GetTraicer return logger -func GetTraicer(ctx context.Context) opentracing.Tracer { +func GetTraicer(ctx context.Context) opentracing.Tracer { // nolint unused return ctx.Value(keyTraicer).(opentracing.Tracer) }