From f7445096451c7e7d917bda65d6303b2eebbd3e8b Mon Sep 17 00:00:00 2001 From: Diversantos Date: Sun, 1 Dec 2024 14:16:17 +0300 Subject: [PATCH] Added some experiments with golang linters --- .../06h_http/internals/app/db/cars_storage.go | 1 - .../cource/06h_http/internals/app/main.go | 5 -- .../cource/06i_code_quality/.golangci.yaml | 25 +++++++++ .../golang/cource/06i_code_quality/Makefile | 6 +++ .../golang/cource/06i_code_quality/go.mod | 3 ++ .../cource/06i_code_quality/someexample.go | 53 +++++++++++++++++++ 6 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 examples/golang/cource/06i_code_quality/.golangci.yaml create mode 100644 examples/golang/cource/06i_code_quality/Makefile create mode 100644 examples/golang/cource/06i_code_quality/go.mod create mode 100644 examples/golang/cource/06i_code_quality/someexample.go diff --git a/examples/golang/cource/06h_http/internals/app/db/cars_storage.go b/examples/golang/cource/06h_http/internals/app/db/cars_storage.go index 4f5aa39..4187aea 100644 --- a/examples/golang/cource/06h_http/internals/app/db/cars_storage.go +++ b/examples/golang/cource/06h_http/internals/app/db/cars_storage.go @@ -68,7 +68,6 @@ func (storage *CarsStorage) GetCarsList(userIdFilter int64, brandFilter string, if licenseFilter != "" { query += fmt.Sprintf(" AND license_plate LIKE $%d", placeholderNum) args = append(args, fmt.Sprintf("%%%s%%", licenseFilter)) - placeholderNum++ } var dbResult []userCar diff --git a/examples/golang/cource/06h_http/internals/app/main.go b/examples/golang/cource/06h_http/internals/app/main.go index c4b5a53..f031042 100644 --- a/examples/golang/cource/06h_http/internals/app/main.go +++ b/examples/golang/cource/06h_http/internals/app/main.go @@ -62,7 +62,6 @@ func (server *AppServer) Serve() { if err != nil { log.Fatalln(err) } - return } func (server *AppServer) Shutdown() { @@ -79,8 +78,4 @@ func (server *AppServer) Shutdown() { } log.Println("Server exited properly.") - - if err == http.ErrServerClosed { - err = nil - } } diff --git a/examples/golang/cource/06i_code_quality/.golangci.yaml b/examples/golang/cource/06i_code_quality/.golangci.yaml new file mode 100644 index 0000000..9e4056a --- /dev/null +++ b/examples/golang/cource/06i_code_quality/.golangci.yaml @@ -0,0 +1,25 @@ + +output: + formats: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters: + enable-all: true + disable: + - stylecheck + - revive + - wsl + - gofmt + - gosimple + - gofumpt + - goimports + - nlreturn + - exportloopref + fast: false + +issues: + exclude-use-default: false + max-issues-per-linter: 100 + max-same-issues: 4 + nes: false diff --git a/examples/golang/cource/06i_code_quality/Makefile b/examples/golang/cource/06i_code_quality/Makefile new file mode 100644 index 0000000..984fff5 --- /dev/null +++ b/examples/golang/cource/06i_code_quality/Makefile @@ -0,0 +1,6 @@ +install: + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2 +lint: + @golangci-lint run ./... -v +lint_autofix: + @GO111MODULE=on $(GOLINT) run ./ -v --fix diff --git a/examples/golang/cource/06i_code_quality/go.mod b/examples/golang/cource/06i_code_quality/go.mod new file mode 100644 index 0000000..072bda2 --- /dev/null +++ b/examples/golang/cource/06i_code_quality/go.mod @@ -0,0 +1,3 @@ +module someexample + +go 1.23.2 diff --git a/examples/golang/cource/06i_code_quality/someexample.go b/examples/golang/cource/06i_code_quality/someexample.go new file mode 100644 index 0000000..5e69bf5 --- /dev/null +++ b/examples/golang/cource/06i_code_quality/someexample.go @@ -0,0 +1,53 @@ +package someexample + +// Person -. +type Person struct { + Name string + Age int +} + +// GetName blah +func (p Person) GetName() string { + return p.Name +} + +type Avatar struct { + URL string + Size int64 +} + +// Client -. +type Client struct { + ID int64 + Img Avatar + Name string + Age int64 +} + +// HasAvatar === +func (c Client) HasAvatar() bool { + if c.Img.URL != "" { + return true + } + return false +} + +// UpdateAvatar ... +func (c *Client) UpdateAvatar() { + c.Img.URL = "new_url" +} + +// GetName -. +func (c Client) GetName() string { + return c.Name +} + +//NewClient -. +func NewClient(name string, age int, img Avatar) *Client { + return &Client{ + ID: 7, + Name: name, + Age: int64(age), + Img: img, + } +}