diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 45a9f1f..5402790 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -3,6 +3,15 @@ name: Go on: [push] jobs: + lint: + name: Lint Golang + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest build: name: Build runs-on: ubuntu-latest @@ -18,9 +27,6 @@ jobs: - name: Get dependencies run: go mod download - - name: Vet - run: go vet -v ./... - - name: Build run: go build -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..65e360a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,359 @@ +# 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: 30m + + # 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 + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: false + + +# 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 + + # make issues output unique by line, default is true + uniq-by-line: true + + # add a prefix to the output file references; default is no prefix + path-prefix: "" + + +# all available settings of specific linters +linters-settings: + depguard: + list-type: blacklist + include-go-root: false + packages: + - "errors" + packages-with-error-messages: + # specify an error message to output when a blacklisted package is used + errors: "use the pkg/errors module instead" + dogsled: + # checks assignments with too many blank identifiers; default is 2 + max-blank-identifiers: 2 + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + errcheck: + # report about not checking of errors in type assertions: `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: false + + exhaustive: + # check switch statements in generated files also + check-generated: false + # indicates that switch statements are to be considered exhaustive if a + # 'default' case is present, even if all enum members aren't listed in the + # switch + default-signifies-exhaustive: false + funlen: + lines: 60 + statements: 40 + gocognit: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + nestif: + # minimal complexity of if statements to report, 5 by default + min-complexity: 5 + goconst: + # minimal length of string constant, 3 by default + min-len: 3 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 3 + + gocyclo: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 30 + godot: + # check all top-level comments, not only declarations + check-all: false + 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 + - TODO + - BUG + - FIXME + - OPTIMIZE # marks code that should be optimized before merging + - HACK # marks hack-arounds that should be removed before merging + 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/finitum/AAAAA + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0.8 + 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 + 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 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + 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'. + 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 + nolintlint: + # Enable to ensure that nolint directives are all used. Default is true. + allow-unused: false + # Disable to ensure that nolint directives don't have a leading space. Default is true. + allow-leading-space: true + # Exclude following linters from requiring an explanation. Default is []. + allow-no-explanation: [] + # Enable to require an explanation of nonzero length after each nolint directive. Default is false. + require-explanation: true + # Enable to require nolint directives to mention the specific linter being suppressed. Default is false. + require-specific: true + rowserrcheck: + packages: + - github.com/jmoiron/sqlx + testpackage: + # regexp pattern to skip files + skip-regexp: (export|internal)_test\.go + 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: false + 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: false + whitespace: + multi-if: false # Enforces newlines (or comments) after every multi-line if statement + multi-func: false # 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 declarations (var) to be cuddled. + allow-cuddle-declarations: false + # Allow trailing comments in ending of blocks + allow-trailing-comment: false + # Force newlines in end of case at this limit (0 = never). + force-case-trailing-whitespace: 0 + # Force cuddling of err checks with err var assignment + force-err-cuddling: false + # Allow leading comments to be separated with empty liens + allow-separated-leading-comment: false + gofumpt: + # Choose whether or not to use the extra rules that are disabled + # by default + extra-rules: false + errorlint: + # Report non-wrapping error creation using fmt.Errorf + errorf: true + +linters: + enable: + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - unused + - varcheck + - bodyclose + - depguard + - cyclop + - dogsled + - dupl + - durationcheck + - errorlint + - exhaustive + - exportloopref + - forcetypeassert + - funlen + - gci + - gochecknoglobals + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - godox + - goerr113 + - gofmt + - gofumpt + - goheader + - golint + - gomnd + - gomodguard + - goprintffuncname + - gosec + - ifshort + - importas + - lll + - makezero + - nakedret + - misspell + - nestif + - nilerr + - noctx + - nolintlint + - paralleltest + - prealloc + - predeclared + - revive + - rowserrcheck + - scopelint + - sqlclosecheck + - stylecheck + - thelper + - tparallel + - unconvert + - unparam + - wastedassign + - whitespace + - wrapcheck + - wsl + disable: + - exhaustivestruct + - interfacer + - maligned + - goimports + + +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 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 + + # The default value is false. If set to true exclude and exclude-rules + # regular expressions become case sensitive. + exclude-case-sensitive: 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 + + +severity: + # Default value is empty string. + # Set the default severity for issues. If severity rules are defined and the issues + # do not match or no severity is provided to the rule this will be the default + # severity applied. Severities should match the supported severity names of the + # selected out format. + # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity + # - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity + # - Github: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message + default-severity: error + + # The default value is false. + # If set to true severity-rules regular expressions become case sensitive. + case-sensitive: false + + # Default value is empty list. + # When a list of severity rules are provided, severity information will be added to lint + # issues. Severity rules have the same filtering capability as exclude rules except you + # are allowed to specify one matcher per severity rule. + # Only affects out formats that support setting severity information. + rules: + - linters: + - dupl + severity: info diff --git a/cmd/builder/main.go b/cmd/builder/main.go index a011681..cdf1afc 100644 --- a/cmd/builder/main.go +++ b/cmd/builder/main.go @@ -2,14 +2,15 @@ package main import ( "encoding/json" - "github.com/finitum/AAAAA/pkg/executor" - "github.com/finitum/AAAAA/pkg/git" - "github.com/finitum/AAAAA/pkg/makepkg" "io/ioutil" "log" "net/http" "os" "strings" + + "github.com/finitum/AAAAA/pkg/executor" + "github.com/finitum/AAAAA/pkg/git" + "github.com/finitum/AAAAA/pkg/makepkg" ) func main() { @@ -41,17 +42,20 @@ func main() { log.Fatalf("Getting HEAD failed: %v", err) } - if err := os.Chdir(dir); err != nil { - log.Fatal("Couldn't cd into git repo") + if cdErr := os.Chdir(dir); cdErr != nil { + log.Fatalf("Couldn't cd into git repo: %v", cdErr) } log.Println("Building package") - if _, _, err := makepkg.Build(); err != nil { - log.Fatalf("Building package failed %v", err) + if _, _, buildErr := makepkg.Build(); buildErr != nil { + log.Fatalf("Building package failed %v", buildErr) } // ls *.pkg.* files, err := ioutil.ReadDir(".") + if err != nil { + log.Fatalf("Building reading current dir %v", err) + } var found string for _, file := range files { fname := file.Name() diff --git a/go.mod b/go.mod index 1f04916..fda825c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/finitum/AAAAA -go 1.15 +go 1.16 require ( github.com/Microsoft/go-winio v0.4.14 // indirect diff --git a/go.sum b/go.sum index e7a1258..f17d3ea 100644 --- a/go.sum +++ b/go.sum @@ -59,14 +59,12 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= -github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgraph-io/ristretto v0.0.3 h1:jh22xisGBjrEVnRZ1DVTpBVQm0Xndu8sMl0CWDzSIBI= github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= @@ -95,7 +93,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -135,7 +132,6 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -252,7 +248,6 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -278,7 +273,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -300,7 +294,6 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -314,14 +307,11 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -332,7 +322,6 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -351,17 +340,14 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 h1:5/PjkGUjvEU5Gl6BxmvKRPpqo2uNMv4rcHBMwzk/st8= golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -389,7 +375,6 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4 h1:Toz2IK7k8rbltAXwNAxKcn9OzqyNfMUhUNjz3sL0NMk= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -401,7 +386,6 @@ google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEn google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= @@ -413,7 +397,6 @@ google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= @@ -452,7 +435,6 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/cmdutil/cmd_test.go b/internal/cmdutil/cmd_test.go index 71de113..ab0cdac 100644 --- a/internal/cmdutil/cmd_test.go +++ b/internal/cmdutil/cmd_test.go @@ -2,15 +2,16 @@ package cmdutil import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestRunCommandStdout(t *testing.T) { stdout, _, err := RunCommand("/bin/bash", "-c", "builtin echo hello") assert.NoError(t, err) assert.Equal(t, "hello\n", stdout) - //assert.Empty(t, stderr) + // assert.Empty(t, stderr) } func TestRunCommandStdErr(t *testing.T) { diff --git a/pkg/aur/aur.go b/pkg/aur/aur.go index 6c24950..6886c98 100644 --- a/pkg/aur/aur.go +++ b/pkg/aur/aur.go @@ -3,14 +3,17 @@ package aur import ( "encoding/json" "fmt" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "net/http" "sort" + + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" ) -const aurInfoQuery = "https://aur.archlinux.org/rpc/?v=5&type=info&arg=%s" -const aurSearchQuery = "https://aur.archlinux.org/rpc/?v=5&type=search&arg=%s" +const ( + aurInfoQuery = "https://aur.archlinux.org/rpc/?v=5&type=info&arg=%s" + aurSearchQuery = "https://aur.archlinux.org/rpc/?v=5&type=search&arg=%s" +) // InfoResolveFunction represents a function that accepts a url and package name, and returns an InfoResult. // If the package is not found on the AUR it should return a NotInAurErr error. diff --git a/pkg/aur/cache.go b/pkg/aur/cache.go index e63dde8..b96ef65 100644 --- a/pkg/aur/cache.go +++ b/pkg/aur/cache.go @@ -3,9 +3,10 @@ package aur import ( "encoding/json" "fmt" + "net/http" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "net/http" ) // NotInAurErr will be returned when the package is not found in the AUR, meaning this dependency diff --git a/pkg/auth/store.go b/pkg/auth/store.go index b1aa25c..7ffe34a 100644 --- a/pkg/auth/store.go +++ b/pkg/auth/store.go @@ -2,11 +2,12 @@ package auth import ( "github.com/dgrijalva/jwt-go" - "github.com/finitum/AAAAA/pkg/models" - "github.com/finitum/AAAAA/pkg/store" "github.com/go-chi/jwtauth" "github.com/pkg/errors" "golang.org/x/crypto/bcrypt" + + "github.com/finitum/AAAAA/pkg/models" + "github.com/finitum/AAAAA/pkg/store" ) type StoreAuth struct { @@ -43,14 +44,13 @@ func (s *StoreAuth) Login(user *models.User) (string, error) { return "", errors.Wrap(err, "user not in database") } - if err := bcrypt.CompareHashAndPassword([]byte(dbUser.Password), []byte(user.Password)); err != nil { - return "", errors.Wrap(err, "password wrong or invalid") + if checkErr := bcrypt.CompareHashAndPassword([]byte(dbUser.Password), []byte(user.Password)); checkErr != nil { + return "", errors.Wrap(checkErr, "password wrong or invalid") } _, tokenString, err := s.jwt.Encode(jwt.StandardClaims{Subject: dbUser.Username, Audience: "user"}) if err != nil { return "", errors.Wrap(err, "couldn't encode jwt token") - } return tokenString, nil diff --git a/pkg/dependency/dep_resolver.go b/pkg/dependency/dep_resolver.go index cfa112e..b823fd8 100644 --- a/pkg/dependency/dep_resolver.go +++ b/pkg/dependency/dep_resolver.go @@ -27,8 +27,9 @@ Basic example: package dependency import ( - "github.com/finitum/AAAAA/pkg/aur" "github.com/pkg/errors" + + "github.com/finitum/AAAAA/pkg/aur" ) // Dependency represents a dependency of an AUR package. @@ -97,7 +98,6 @@ func (r *aurResolver) resolveInternal(pkg string) error { // Go through all dependencies for _, dep := range deps { if _, exists := r.deps[dep]; !exists { - if err := r.resolveInternal(dep); err != nil { return errors.Wrapf(err, "failed to resolve dependency %s", dep) } diff --git a/pkg/dependency/dep_resolver_test.go b/pkg/dependency/dep_resolver_test.go index 0d8bd24..9292e57 100644 --- a/pkg/dependency/dep_resolver_test.go +++ b/pkg/dependency/dep_resolver_test.go @@ -3,11 +3,13 @@ package dependency import ( "errors" "fmt" - "github.com/finitum/AAAAA/pkg/aur" - "github.com/stretchr/testify/assert" "sort" "testing" "time" + + "github.com/stretchr/testify/assert" + + "github.com/finitum/AAAAA/pkg/aur" ) func testInfoResolver(_, pkg string) (aur.InfoResult, error) { diff --git a/pkg/dependency/iterator.go b/pkg/dependency/iterator.go index aa3a308..152e0b2 100644 --- a/pkg/dependency/iterator.go +++ b/pkg/dependency/iterator.go @@ -42,7 +42,7 @@ func (it *Iterator) Next() bool { } // Should be safe, as this struct is the only thing directly accessing the queue - it.next = res[0].(Dependency) + it.next, _ = res[0].(Dependency) return true } diff --git a/pkg/dependency/iterator_test.go b/pkg/dependency/iterator_test.go index c10c27f..77ad9e3 100644 --- a/pkg/dependency/iterator_test.go +++ b/pkg/dependency/iterator_test.go @@ -1,8 +1,9 @@ package dependency import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestNext(t *testing.T) { diff --git a/pkg/executor/docker.go b/pkg/executor/docker.go index 34e00b5..493d84e 100644 --- a/pkg/executor/docker.go +++ b/pkg/executor/docker.go @@ -3,12 +3,13 @@ package executor import ( "context" "encoding/json" + "sync" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "sync" ) type DockerExecutor struct { diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index a0edd8b..c59ea37 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -2,6 +2,7 @@ package executor import ( "context" + "github.com/finitum/AAAAA/pkg/models" ) diff --git a/pkg/executor/kubernetes.go b/pkg/executor/kubernetes.go index e7b1d69..849ac8d 100644 --- a/pkg/executor/kubernetes.go +++ b/pkg/executor/kubernetes.go @@ -3,13 +3,14 @@ package executor import ( "context" "encoding/json" + "time" + "github.com/pkg/errors" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" - "time" ) type KubernetesExecutor struct { diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go index 212e520..ef5fc74 100644 --- a/pkg/git/git_test.go +++ b/pkg/git/git_test.go @@ -2,8 +2,9 @@ package git import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestLatestSHA(t *testing.T) { diff --git a/pkg/models/models.go b/pkg/models/models.go index cfbf0b4..84d7a8f 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -2,12 +2,13 @@ package models import ( "errors" - "github.com/go-git/go-git/v5/plumbing" "net/http" "time" + + "github.com/go-git/go-git/v5/plumbing" ) -// Pkg is an archlinux package +// Pkg is an archlinux package. type Pkg struct { // Name is the name of the package (unique) Name string @@ -25,12 +26,12 @@ type Pkg struct { // TODO: Version? } -// Render will run before marshalling a Pkg, good place to do pre-processing +// Render will run before marshalling a Pkg, good place to do pre-processing. func (p *Pkg) Render(http.ResponseWriter, *http.Request) error { return nil } -// Bind will run after unmarshalling a Pkg, good place to do post-processing +// Bind will run after unmarshalling a Pkg, good place to do post-processing. func (p *Pkg) Bind(*http.Request) error { if p.Name == "" || p.RepoURL == "" { return errors.New("package is missing required fields Name and/or RepoURL") diff --git a/pkg/repo_add/repoadd.go b/pkg/repo_add/repoadd.go index d38c103..9427727 100644 --- a/pkg/repo_add/repoadd.go +++ b/pkg/repo_add/repoadd.go @@ -3,13 +3,17 @@ package repo_add import ( - "github.com/finitum/AAAAA/internal/cmdutil" - "github.com/pkg/errors" "os/exec" + + "github.com/pkg/errors" + + "github.com/finitum/AAAAA/internal/cmdutil" ) -const repoAddCommand string = "repo-add" -const repoRemoveCommand string = "repo-remove" +const ( + repoAddCommand string = "repo-add" + repoRemoveCommand string = "repo-remove" +) // CommonOptions are options that are common to the repo-add and repo-remove commands. // Derived from https://www.archlinux.org/pacman/repo-add.8.html diff --git a/pkg/repo_add/repoadd_test.go b/pkg/repo_add/repoadd_test.go index d2dd5a3..98ed260 100644 --- a/pkg/repo_add/repoadd_test.go +++ b/pkg/repo_add/repoadd_test.go @@ -1,16 +1,16 @@ package repo_add import ( - "github.com/stretchr/testify/assert" - "golang.org/x/sys/unix" "os" "os/exec" "testing" + + "github.com/stretchr/testify/assert" + "golang.org/x/sys/unix" ) func TestNewRepoAdd(t *testing.T) { _, err := NewRepoAdd("test") - // If NewRepoAdd fails, the tests don't run on an arch system. // By returning the test just passes on non Archlinux systems if err != nil { @@ -24,7 +24,6 @@ func TestIntegration(t *testing.T) { pkgbuildpath := dir + "/PKGBUILD" repo, err := NewRepoAdd(dbpath) - // If NewRepoAdd fails, the tests don't run on an arch system. // By returning the test just passes on non Archlinux systems if err != nil { @@ -73,6 +72,6 @@ provides=('dummy=0.1')`) // TODO: This test should actually assert things about the database // I did manually check it working, but that't not really enough is it :P - //err = os.RemoveAll(dir) + // err = os.RemoveAll(dir) assert.NoError(t, err) } diff --git a/pkg/store/badger.go b/pkg/store/badger.go index 359828b..5d57c19 100644 --- a/pkg/store/badger.go +++ b/pkg/store/badger.go @@ -2,15 +2,16 @@ package store import ( "context" + "time" + "github.com/dgraph-io/badger/v2" "github.com/pkg/errors" log "github.com/sirupsen/logrus" - "time" ) const gcTime = 5 * time.Minute -// Badger is a Store based on dgraph's badger +// Badger is a Store based on dgraph's badger. type Badger struct { db *badger.DB } diff --git a/pkg/store/badger_cache.go b/pkg/store/badger_cache.go index 6a46833..34ff941 100644 --- a/pkg/store/badger_cache.go +++ b/pkg/store/badger_cache.go @@ -4,8 +4,9 @@ import ( "bytes" "encoding/gob" "github.com/dgraph-io/badger/v2" - "github.com/finitum/AAAAA/pkg/aur" "github.com/pkg/errors" + + "github.com/finitum/AAAAA/pkg/aur" ) func (b *Badger) SetResultsEntry(searchterm string, result aur.Results) error { diff --git a/pkg/store/badger_store.go b/pkg/store/badger_store.go index 7b8b34f..dd584c0 100644 --- a/pkg/store/badger_store.go +++ b/pkg/store/badger_store.go @@ -3,9 +3,11 @@ package store import ( "bytes" "encoding/gob" + "github.com/dgraph-io/badger/v2" - "github.com/finitum/AAAAA/pkg/models" "github.com/pkg/errors" + + "github.com/finitum/AAAAA/pkg/models" ) func (b *Badger) GetPackage(name string) (*models.Pkg, error) { @@ -139,7 +141,6 @@ func (b *Badger) AllUsers() (users []*models.User, _ error) { users = append(users, &user) return nil }) - if err != nil { return errors.Wrap(err, "value") } diff --git a/pkg/store/badger_store_test.go b/pkg/store/badger_store_test.go index 02a66c0..f6376b1 100644 --- a/pkg/store/badger_store_test.go +++ b/pkg/store/badger_store_test.go @@ -1,12 +1,14 @@ package store import ( - "github.com/finitum/AAAAA/pkg/models" - "github.com/go-git/go-git/v5/plumbing" - "github.com/stretchr/testify/assert" "os" "testing" "time" + + "github.com/go-git/go-git/v5/plumbing" + "github.com/stretchr/testify/assert" + + "github.com/finitum/AAAAA/pkg/models" ) func TestBadger_AddGetDelPackage(t *testing.T) { diff --git a/pkg/store/ristretto_cache.go b/pkg/store/ristretto_cache.go index bd92cc1..bc8ab0b 100644 --- a/pkg/store/ristretto_cache.go +++ b/pkg/store/ristretto_cache.go @@ -2,15 +2,16 @@ package store import ( "github.com/dgraph-io/ristretto" - "github.com/finitum/AAAAA/pkg/aur" "github.com/pkg/errors" + + "github.com/finitum/AAAAA/pkg/aur" ) type Ristretto struct { cache *ristretto.Cache } -// NewRistretto creates a new Cache based on ristretto +// NewRistretto creates a new Cache based on ristretto. func NewRistretto() (*Ristretto, error) { // TODO: these are sane defaults, we may want to make them configurable cache, err := ristretto.NewCache(&ristretto.Config{ diff --git a/pkg/store/store.go b/pkg/store/store.go index af5a306..32a4a48 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -1,17 +1,19 @@ package store import ( + "time" + + "github.com/pkg/errors" + "github.com/finitum/AAAAA/pkg/aur" "github.com/finitum/AAAAA/pkg/models" - "github.com/pkg/errors" - "time" ) // ErrNotExists is the error returned by the Store or Cache if an entry can not be found, this is useful because it // isn't always considered an error if no entry exists. var ErrNotExists = errors.New("entry does not exist") -// Store is a combined interface of PackageStore and UserStore, this is the store the control_plane needs +// Store is a combined interface of PackageStore and UserStore, this is the store the control_plane needs. type Store interface { PackageStore UserStore @@ -47,12 +49,14 @@ type UserStore interface { AllUserNames() ([]string, error) } -// cacheTTL is the TTL of cache entries -const cacheTTL = 30 * time.Minute -const resultsPrefix = "results_" -const infoPrefix = "info_" +// cacheTTL is the TTL of cache entries. +const ( + cacheTTL = 30 * time.Minute + resultsPrefix = "results_" + infoPrefix = "info_" +) -// Cache interface for caching aur rpc results +// Cache interface for caching aur rpc results. type Cache interface { // SetResultsEntry, add an aur result cache entry SetResultsEntry(term string, result aur.Results) error @@ -68,7 +72,7 @@ type Cache interface { GetInfoEntry(name string) (*aur.InfoResult, error) } -// GetPartialCacheEntry gets a cache entry even if the term only partially matches the prefix +// GetPartialCacheEntry gets a cache entry even if the term only partially matches the prefix. func GetPartialCacheEntry(cache Cache, term string) (aur.Results, bool, error) { exact := true diff --git a/services/aur_cache/main.go b/services/aur_cache/main.go index 03ed30e..943bfab 100644 --- a/services/aur_cache/main.go +++ b/services/aur_cache/main.go @@ -2,16 +2,18 @@ package main import ( "context" - "github.com/finitum/AAAAA/internal/cors" - "github.com/finitum/AAAAA/pkg/aur" - "github.com/finitum/AAAAA/pkg/store" + "net/http" + "os" + "strings" + "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/go-chi/render" log "github.com/sirupsen/logrus" - "net/http" - "os" - "strings" + + "github.com/finitum/AAAAA/internal/cors" + "github.com/finitum/AAAAA/pkg/aur" + "github.com/finitum/AAAAA/pkg/store" ) func init() { @@ -46,7 +48,11 @@ func main() { if err != nil { log.Fatalf("Couldn't open ristretto cache: %v", err) } - defer badger.Close() + defer func() { + if err := badger.Close(); err != nil { + log.Warnf("Error closing badger: %v", err) + } + }() badger.StartGC(ctx) cache = badger } diff --git a/services/control_server/config/config.go b/services/control_server/config/config.go index e10a712..be3b1cb 100644 --- a/services/control_server/config/config.go +++ b/services/control_server/config/config.go @@ -1,12 +1,13 @@ package config import ( - log "github.com/sirupsen/logrus" "os" "path" + + log "github.com/sirupsen/logrus" ) -// Config is the configuration used by the control server +// Config is the configuration used by the control server. type Config struct { // StoreLocation is the Location where the database is stored StoreLocation string @@ -28,7 +29,7 @@ type Config struct { KubeNamespace string `json:",omitempty"` } -// DevDefault returns a default set of config values which generally work for local development +// DevDefault returns a default set of config values which generally work for local development. func DevDefault() *Config { root := "./AAAAA/" diff --git a/services/control_server/main.go b/services/control_server/main.go index 973c1b4..90feeb5 100644 --- a/services/control_server/main.go +++ b/services/control_server/main.go @@ -3,7 +3,15 @@ package main import ( "crypto/rand" "encoding/base64" + "net/http" + "github.com/dgrijalva/jwt-go" + "github.com/go-chi/chi" + "github.com/go-chi/chi/middleware" + "github.com/go-chi/jwtauth" + "github.com/go-chi/render" + log "github.com/sirupsen/logrus" + "github.com/finitum/AAAAA/internal/cors" "github.com/finitum/AAAAA/pkg/auth" "github.com/finitum/AAAAA/pkg/executor" @@ -11,12 +19,6 @@ import ( "github.com/finitum/AAAAA/pkg/store" "github.com/finitum/AAAAA/services/control_server/config" "github.com/finitum/AAAAA/services/control_server/routes" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" - "github.com/go-chi/jwtauth" - "github.com/go-chi/render" - log "github.com/sirupsen/logrus" - "net/http" ) func main() { @@ -30,7 +32,11 @@ func main() { if err != nil { log.Fatalf("Opening Badger store failed: %v", err) } - defer db.Close() + defer func() { + if dbErr := db.Close(); dbErr != nil { + log.Warnf("Error closing db: %v", dbErr) + } + }() tokenAuth := jwtauth.New(jwt.SigningMethodHS384.Name, []byte(cfg.JWTKey), nil) @@ -62,7 +68,7 @@ func main() { r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Use(cors.AllowAll) - //r.Use(middleware.Compress(5)) + // r.Use(middleware.Compress(5)) r.Use(render.SetContentType(render.ContentTypeJSON)) @@ -78,7 +84,7 @@ func main() { // Handle valid / invalid tokens. r.Use(jwtauth.Authenticator) - //r.Use(corsHandler) + // r.Use(corsHandler) r.Post("/user", rs.AddUser) r.Delete("/user/{username}", rs.DeleteUser) diff --git a/services/control_server/routes/errors.go b/services/control_server/routes/errors.go index 1781409..76954b3 100644 --- a/services/control_server/routes/errors.go +++ b/services/control_server/routes/errors.go @@ -1,8 +1,9 @@ package routes import ( - "github.com/go-chi/render" "net/http" + + "github.com/go-chi/render" ) type AppCode int64 diff --git a/services/control_server/routes/package.go b/services/control_server/routes/package.go index ef2b6cb..8833360 100644 --- a/services/control_server/routes/package.go +++ b/services/control_server/routes/package.go @@ -3,19 +3,21 @@ package routes import ( "context" "errors" - "github.com/finitum/AAAAA/pkg/executor" - "github.com/finitum/AAAAA/pkg/git" - "github.com/finitum/AAAAA/pkg/models" - "github.com/finitum/AAAAA/pkg/repo_add" - "github.com/finitum/AAAAA/pkg/store" + "io" + "net/http" + "os" + "github.com/go-chi/chi" "github.com/go-chi/jwtauth" "github.com/go-chi/render" "github.com/go-git/go-git/v5/plumbing" log "github.com/sirupsen/logrus" - "io" - "net/http" - "os" + + "github.com/finitum/AAAAA/pkg/executor" + "github.com/finitum/AAAAA/pkg/git" + "github.com/finitum/AAAAA/pkg/models" + "github.com/finitum/AAAAA/pkg/repo_add" + "github.com/finitum/AAAAA/pkg/store" ) func (rs *Routes) GetPackages(w http.ResponseWriter, r *http.Request) { @@ -157,17 +159,17 @@ func (rs *Routes) UploadPackage(w http.ResponseWriter, r *http.Request) { // Download file pkgPath := rs.cfg.RepoLocation + "/" + filename if externalUrl == "" { - file, err := os.Create(pkgPath) - if err != nil { - _ = render.Render(w, r, ErrServerError(err)) - log.Warnf("UploadPackage creating file failed: %v", err) + file, createErr := os.Create(pkgPath) + if createErr != nil { + _ = render.Render(w, r, ErrServerError(createErr)) + log.Warnf("UploadPackage creating file failed: %v", createErr) return } // or fs.CopyStream if this returns ErrUnexpectedEof - if _, err := io.Copy(file, r.Body); err != nil { - _ = render.Render(w, r, ErrServerError(err)) - log.Warnf("UploadPackage writing to file failed: %v", err) + if _, copyErr := io.Copy(file, r.Body); copyErr != nil { + _ = render.Render(w, r, ErrServerError(copyErr)) + log.Warnf("UploadPackage writing to file failed: %v", copyErr) return } } else { @@ -175,9 +177,9 @@ func (rs *Routes) UploadPackage(w http.ResponseWriter, r *http.Request) { } pkg.LastHash = plumbing.NewHash(hash) - if err := rs.db.AddPackage(pkg); err != nil { - _ = render.Render(w, r, ErrServerError(err)) - log.Warnf("UploadPackage updating db failed: %v", err) + if addPackageErr := rs.db.AddPackage(pkg); addPackageErr != nil { + _ = render.Render(w, r, ErrServerError(addPackageErr)) + log.Warnf("UploadPackage updating db failed: %v", addPackageErr) return } diff --git a/services/control_server/routes/routes.go b/services/control_server/routes/routes.go index 9475bdf..789c5f9 100644 --- a/services/control_server/routes/routes.go +++ b/services/control_server/routes/routes.go @@ -1,11 +1,12 @@ package routes import ( + "net/http" + "github.com/finitum/AAAAA/pkg/auth" "github.com/finitum/AAAAA/pkg/executor" "github.com/finitum/AAAAA/pkg/store" "github.com/finitum/AAAAA/services/control_server/config" - "net/http" ) type Routes struct { diff --git a/services/control_server/routes/user.go b/services/control_server/routes/user.go index 216373d..8eae4c8 100644 --- a/services/control_server/routes/user.go +++ b/services/control_server/routes/user.go @@ -2,11 +2,13 @@ package routes import ( "encoding/json" - "github.com/finitum/AAAAA/pkg/models" + "net/http" + "github.com/go-chi/chi" "github.com/go-chi/render" log "github.com/sirupsen/logrus" - "net/http" + + "github.com/finitum/AAAAA/pkg/models" ) func (rs *Routes) Login(w http.ResponseWriter, r *http.Request) { @@ -90,7 +92,6 @@ func (rs *Routes) DeleteUser(w http.ResponseWriter, r *http.Request) { _ = render.Render(w, r, ErrServerError(err)) log.Errorf("failed to remove user (%v)", err) } - } func (rs *Routes) UpdateUser(w http.ResponseWriter, r *http.Request) {