-
Notifications
You must be signed in to change notification settings - Fork 1
Fix some basic tech debt #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
5f09103
Fix file formatting with gofumpt -w -s
invidian d8684ec
.golangci.yml: initial commit
invidian 51eb3a7
.github/workflows/go.yml: rename build job to test
invidian 649d5d4
.github/workflows/go.yml: add lint job
invidian bfea7cf
pkg/client: fix error wrapping on error unmarshalling
invidian 10f3403
.golangci.yml: re-enable errorlint linter
invidian 157b784
pkg/client: improve name of URL variable and struct field
invidian 8282967
pkg/client: rename variable ID -> id
invidian a674d0d
.golangci.yml: enable gocritic linter
invidian 8985817
pkg/client: run all tests in parallel
invidian d8c467d
.golangci.yml: enable paralleltest linter
invidian 0bfa3bb
pkg/client: add missing dots in comments
invidian 3bf6988
.golangci.yml: enable godot linter
invidian 01e4719
pkg/client: improve formatting
invidian 24c0c4a
.golangci.yml: enable wsl linter
invidian 860d78c
Consistently write FleetLock as "FleetLock" when possible
invidian 5360680
pkg/client: fix ClientParams documentation styling
invidian 2206f52
Add basic package comments
invidian b71ff23
.golangci.yml: enable stylecheck linter
invidian 2614160
pkg/client: fix typo identifer -> identifier
invidian f968900
.golangci.yml: enable misspell linter
invidian 4704413
pkg/client: fix too long line and duplicated error string in tests
invidian eb66470
.golangci.yml: enable lll linter
invidian e87e1b2
pkg/client/client_test.go: improve formatting
invidian 465076d
.golangci.yml: enable nlreturn linter
invidian 988ef1c
pkg/client: rename ClientParams struct to just Params
invidian a79a6a0
cmd: add comment for exported variable Root
invidian 3ed8192
.golangci.yml: enable revive linter
invidian e5fbfda
pkg/client: add nolint tag for client_params JSON field
invidian 8d9945c
.golangci.yml: enable tagliatelle linter
invidian aad369a
cmd: don't use global variables and init functions
invidian 3a3b997
.golangci.yml: enable gochecknoglobals and gochecknoinits variables
invidian 4fa57ee
.golangci.yml: exclude false-positives from paralleltest linter
invidian 16a7d15
pkg/client: refactor client tests to avoid cases duplication
invidian 02529f5
.golangci.yml: enable dupl linter
invidian bc5e637
pkg/client: remove unreachable code from handling response
invidian 92a646f
.golangci.yml: enable govet linter
invidian d51ff0f
pkg/client: add nolint comment on closing response body
invidian 655b49d
pkg/client: add error handling in tests
invidian 2c3dc97
.golangci.yml: enable errcheck linter
invidian 298a8f8
.golangci.yml: enable extra linter settings
invidian c462242
pkg/client: accept context for operations
invidian 3b472be
.golangci.yml: enable noctx linter
invidian b167c5e
pkg/client: get rid of magic numbers for HTTP response codes
invidian 507dc95
.golangci.yml: enable gomnd linter
invidian 3f2ab41
.golangci.yml: update list of linters
invidian f170b88
Makefile: add targets for validating golangci-lint configuration
invidian 42eb797
.github/workflows/go.yml: check if list of linters is up to date
invidian 86a59b3
Makefile: don't run build in parallel
invidian 2ce5c53
Makefile: add help target
invidian 2ff0ffc
.github/workflows/go.yml: add spell checking job
invidian 421638c
pkg/client: move exported functions to the top of the file
invidian fc4b824
cmd: improve description of id flag
invidian 60bf0cb
main.go: exit with error exit code on execution error
invidian a1262c8
main.go: don't print error message twice
invidian 0e1c5d3
cmd: add description for subcommands
invidian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| output: | ||
| sort-results: true | ||
|
|
||
| issues: | ||
| exclude-use-default: false | ||
| max-same-issues: 0 | ||
| max-issues-per-linter: 0 | ||
| exclude-rules: | ||
| # False positive: https://github.com/kunwardeep/paralleltest/issues/8. | ||
| - linters: | ||
| - paralleltest | ||
| text: "does not use range value in test Run" | ||
|
|
||
| linters-settings: | ||
| errcheck: | ||
| check-type-assertions: true | ||
| check-blank: true | ||
| gci: | ||
| local-prefixes: github.com/flatcar-linux/fleetlock | ||
| godot: | ||
| capital: true | ||
| gofumpt: | ||
| extra-rules: true | ||
| govet: | ||
| enable-all: true | ||
| disable: | ||
| - fieldalignment | ||
| - shadow | ||
| makezero: | ||
| always: true | ||
| nolintlint: | ||
| allow-leading-space: false | ||
| require-explanation: true | ||
| require-specific: true | ||
| wsl: | ||
| force-err-cuddling: true | ||
|
|
||
| linters: | ||
| disable-all: false | ||
| disable: | ||
| # We do not have clearly defined error types yet. | ||
| - goerr113 | ||
| # We do not require all used structs to have all fields initialized. | ||
| - exhaustivestruct | ||
| # This linters has been deprecated. | ||
| - interfacer | ||
| - maligned | ||
| - golint | ||
| enable: | ||
| - asciicheck | ||
| - bodyclose | ||
| - cyclop | ||
| - deadcode | ||
| - depguard | ||
| - dogsled | ||
| - dupl | ||
| - durationcheck | ||
| - errcheck | ||
| - errname | ||
| - errorlint | ||
| - exhaustive | ||
| - exportloopref | ||
| - forbidigo | ||
| - forcetypeassert | ||
| - funlen | ||
| - gci | ||
| - gochecknoglobals | ||
| - gochecknoinits | ||
| - gocognit | ||
| - goconst | ||
| - gocritic | ||
| - gocyclo | ||
| - godot | ||
| - godox | ||
| - gofmt | ||
| - gofumpt | ||
| - goheader | ||
| - goimports | ||
| - gomnd | ||
| - gomoddirectives | ||
| - gomodguard | ||
| - goprintffuncname | ||
| - ifshort | ||
| - importas | ||
| - ineffassign | ||
| - lll | ||
| - makezero | ||
| - misspell | ||
| - nakedret | ||
| - nestif | ||
| - nilerr | ||
| - nlreturn | ||
| - noctx | ||
| - nolintlint | ||
| - paralleltest | ||
| - prealloc | ||
| - predeclared | ||
| - promlinter | ||
| - revive | ||
| - rowserrcheck | ||
| - scopelint | ||
| - sqlclosecheck | ||
| - structcheck | ||
| - stylecheck | ||
| - tagliatelle | ||
| - testpackage | ||
| - thelper | ||
| - tparallel | ||
| - typecheck | ||
| - unconvert | ||
| - unparam | ||
| - varcheck | ||
| - wastedassign | ||
| - whitespace | ||
| - wrapcheck | ||
| - wsl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,24 @@ | ||
| build: | ||
| GOLANGCILINT := go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1 | ||
|
|
||
| .PHONY: build | ||
| build: ## Compiles CLI binary. | ||
| @go build -o ./fleetlockctl main.go | ||
|
|
||
| .PHONY: test-working-tree-clean | ||
| test-working-tree-clean: ## Checks if working directory is clean. | ||
| @test -z "$$(git status --porcelain)" || (echo "Commit all changes before running this target"; exit 1) | ||
|
|
||
| .PHONY: update-linters | ||
| update-linters: ## Updates list of linters in .golangci.yml file based on currently installed golangci-lint binary. | ||
tormath1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Remove all enabled linters. | ||
| sed -i '/^ enable:/q0' .golangci.yml | ||
| # Then add all possible linters to config. | ||
| $(GOLANGCILINT) linters | grep -E '^\S+:' | cut -d: -f1 | sort | sed 's/^/ - /g' | grep -v -E "($$(grep '^ disable:' -A 100 .golangci.yml | grep -E ' - \S+$$' | awk '{print $$2}' | tr \\n '|' | sed 's/|$$//g'))" >> .golangci.yml | ||
|
|
||
| .PHONY: test-update-linters | ||
| test-update-linters: test-working-tree-clean update-linters ## Verifies that list of linters in .golangci.yml file is up to date. | ||
| @test -z "$$(git status --porcelain)" || (echo "Linter configuration outdated. Run 'make update-linters' and commit generated changes to fix."; exit 1) | ||
|
|
||
| .PHONY: help | ||
| help: ## Prints help message. | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,22 @@ | ||
| // Package cmd implements fleetlockctl CLI. | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| group, id, url string | ||
| // Command returns CLI command to be executed. | ||
| func Command() *cobra.Command { | ||
| cli := &cobra.Command{Use: "fleetlockctl"} | ||
|
|
||
| Root = &cobra.Command{Use: "fleetlockctl"} | ||
| ) | ||
| var group, id, url string | ||
|
|
||
| cli.PersistentFlags().StringVarP(&group, "group", "g", "default", "FleetLock group") | ||
| cli.PersistentFlags().StringVarP(&id, "id", "i", "", "FleetLock instance ID (e.g. content of /etc/machine-id file)") | ||
| cli.PersistentFlags().StringVarP(&url, "url", "u", "", "FleetLock endpoint URL") | ||
|
|
||
| func init() { | ||
| Root.PersistentFlags().StringVarP(&group, "group", "g", "default", "Fleet-Lock group") | ||
| Root.PersistentFlags().StringVarP(&id, "id", "i", "", "Fleet-Lock instance ID (/etc/machine-id for example)") | ||
| Root.PersistentFlags().StringVarP(&url, "url", "u", "", "Fleet-Lock endpoint URL") | ||
| cli.AddCommand(lock(&group, &id, &url)) | ||
| cli.AddCommand(unlock(&group, &id, &url)) | ||
|
|
||
| Root.AddCommand(lock) | ||
| Root.AddCommand(unlock) | ||
| return cli | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,13 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/flatcar-linux/fleetlock/cmd" | ||
| ) | ||
|
|
||
| func main() { | ||
| if err := cmd.Root.Execute(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "unable to execute command: %v", err) | ||
| if err := cmd.Command().Execute(); err != nil { | ||
| os.Exit(1) | ||
invidian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.