From 899172ddb9cd0c026b9381272a55863c70ebd2a7 Mon Sep 17 00:00:00 2001 From: Vivcharyk Myroslav Date: Wed, 1 May 2024 20:40:32 +0200 Subject: [PATCH] Initial commit --- .github/workflows/ci.yaml | 55 +++++++++++++++++++++ .gitignore | 11 +++++ .golangci.yml | 101 ++++++++++++++++++++++++++++++++++++++ Makefile | 26 ++++++++++ README.md | 16 ++++++ Taskfile.yml | 26 ++++++++++ go.mod | 5 ++ go.sum | 4 ++ main.go | 7 +++ 9 files changed, 251 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 Makefile create mode 100644 README.md create mode 100644 Taskfile.yml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1ce93b9 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,55 @@ +name: Lint and Test +on: + push: + branches: + - main + pull_request: + +env: + GO_VERSION: "1.22.x" + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: lint + uses: golangci/golangci-lint-action@v3 + + test: + name: test + needs: lint + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Go cache + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ env.GO_VERSION }}-cache + + - name: Install Task + uses: arduino/setup-task@v1 + with: + version: 3.x + + - name: Test + run: task test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2e69c28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/.DS_Store +/.idea/ + +/bin/* +/.env + +/.serverless +/terraform/.terraform.lock.hcl +/terraform/.terraform/ +/unit.coverprofile +/credentials.json diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..1f146ee --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,101 @@ +run: + go: '1.22' + timeout: 5m + +linters-settings: + errcheck: + check-type-assertions: true + govet: + enable: + - fieldalignment + goconst: + min-len: 2 + min-occurrences: 2 + misspell: + locale: US + lll: + line-length: 140 + gocritic: + enabled-tags: + - performance + - style + - experimental + - opinionated + +linters: + disable-all: true + enable: + - bodyclose + - containedctx + - copyloopvar + - cyclop + - dogsled + - dupl + - errcheck + - errchkjson + - errname + - exhaustive + - exportloopref + - gas + - gci + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - gosec + - gosimple + - govet + - importas + - ineffassign + - interfacebloat + - loggercheck + - megacheck + - mirror + - misspell + - nakedret + - nestif + - noctx + - prealloc + - reassign + - revive + - sloglint + - staticcheck + - stylecheck + - tagliatelle + - tenv + - testifylint + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - unused + - whitespace + - wrapcheck + - wsl + fast: false + +issues: + exclude-rules: + - text: "at least one file in a package should have a package comment" + linters: + - stylecheck + - text: "should have a package comment" + linters: + - revive + - text: "should have comment or be unexported" + linters: + - revive + - text: "whyNoLint" + linters: + - gocritic + - path: _test\.go + linters: + - gosec + - dupl + - cyclop + - govet + exclude-files: + - "mock_.+\\.go" + exclude-use-default: false \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4eb0566 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +BUILD_DIR ?= out +VENDOR_DIR = vendor + +GOLANGCI_LINT_VERSION ?= 1.55.1 + +GO ?= go +GOLANGCI_LINT ?= golangci-lint + +all: clean +.PHONY: all + +clean: + @rm -f ./bin/* + +.PHONY: test +test: test-unit + +## Run unit tests +.PHONY: test-unit +test-unit: + @echo ">> Unit test" + @$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./... + +lint: + @echo ">> Linting" + @$(GOLANGCI_LINT) run \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..194b4e2 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +[![Action Status](https://github.com/vmyroslav/go-template/actions/workflows/ci.yaml/badge.svg)](https://github.com/vmyroslav/go-template/actions/workflows/ci.yaml) + +# Project + +## List of useful commands: + +* `task help` - shows the list of all available commands + +### Prerequisites + +- Go version 1.22 or later +- Taskfile for task running + +### Installing + +A step by step series of examples that tell you how to get a development environment running. \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..7cb8035 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,26 @@ +version: '3' + +dotenv: ['.env'] # take variables from .env file + +env: + OK_COLOR: '\033[32;01m' + NO_COLOR: '\033[0m' + +tasks: + default: + cmds: + - task --list-all + lint: + cmds: + - golangci-lint run -c .golangci.yml + test: + cmds: + - go test -gcflags=-l -covermode=atomic -race ./... + update-deps: + desc: Update dependencies + cmds: + - go get -u -d ./... + fumpt: + desc: Gofumpt project files + cmds: + - find . -name '*.go' -type f -exec gofumpt -w {} + \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..34381d1 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module home-bartender-back + +go 1.22 + +require github.com/vmyroslav/home-lib v0.1.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..511de29 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/vmyroslav/home-lib v0.0.0-20231113100224-567b61697473 h1:k26CnMh1z7duzbKO8Pvw/jXHmJ2+R5w4G5kmRfXC86c= +github.com/vmyroslav/home-lib v0.0.0-20231113100224-567b61697473/go.mod h1:+8aMxDeF9QZCA+r3lCnAd0o3V3oq7b5rTs5WhzNGTjE= +github.com/vmyroslav/home-lib v0.1.0 h1:rd7AHHcbH5eWveW3XDfLh+6gDY/604dmJl7CNGQHzgM= +github.com/vmyroslav/home-lib v0.1.0/go.mod h1:YqjLu07ymd+i53pztQXD43T8nrROg5CTe1eQyGTYbd8= diff --git a/main.go b/main.go new file mode 100644 index 0000000..9dea239 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, playground") +}