diff --git a/.github/workflows/full-test-suite.yml b/.github/workflows/full-test-suite.yml new file mode 100644 index 0000000..1ab05ce --- /dev/null +++ b/.github/workflows/full-test-suite.yml @@ -0,0 +1,25 @@ +name: playground-mono-test-suite +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.23.x" + - name: Install dependencies + run: go get . + - name: Build + run: make build + - name: Run Unit tests + run: make unittest +# - name: Run Integration tests +# run: make test diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..ce3c57a --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,24 @@ +name: linter +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +permissions: + contents: read + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60.1 diff --git a/.gitignore b/.gitignore index 09e3868..c580267 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ .vscode/ .env +./playground-mono diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..13fa95a --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,142 @@ +run: + concurrency: 8 + + timeout: 5m + + issues-exit-code: 1 + + tests: false + + modules-download-mode: readonly + + allow-parallel-runners: false + + go: "" # keep this empty to use the Go version from the go.mod file. + +linters: + fast: false # set to true runs only fast linters. + + disable-all: true + + enable: + - bodyclose + - dogsled + - dupl + - errcheck + - exportloopref + - funlen + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - goprintffuncname + - gosec + - gosimple + - revive + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + +linters-settings: + dupl: + threshold: 200 + + funlen: + lines: 200 + statements: 200 + + goconst: + min-len: 2 + min-occurrences: 2 + + gocognit: + # minimal code complexity to report, 30 by default (but we recommend 10-20) + min-complexity: 10 + + gocyclo: + min-complexity: 30 + + lll: + tab-width: 2 + line-length: 200 + + misspell: + locale: US + + nolintlint: + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + - nestingReduce + + revive: + # see https://github.com/mgechev/revive#available-rules for details. + ignore-generated-header: true + severity: error + confidence: 0.8 + rules: + - name: indent-error-flow + - name: errorf + - name: unexported-return + - name: error-naming + - name: error-return + - name: empty-lines + - name: empty-block + - name: context-as-argument + - name: if-return + - name: superfluous-else + + staticcheck: + checks: ["all"] + +output: + print-issued-lines: false + + print-linter-name: true + + uniq-by-line: false + + sort-results: true + +issues: + max-issues-per-linter: 0 + + max-same-issues: 0 + + new: false + + fix: true + + exclude-dirs: + - .github + - .hooks + - .vscode + + exclude-files: + - README.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..18d8dee --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + +- repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-fmt + - id: golangci-lint + - id: go-mod-tidy diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..310580e --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +.PHONY: build test build-docker run test-one + +build: + CGO_ENABLED=0 GOOS=linux go build -o ./playground-mono + +format: + go fmt ./... + +run: + go run main.go + +# TODO: Uncomment once integration-tests are added +#test: +# go test -v -count=1 -p=1 ./integration_tests/... +# +#test-one: +# go test -v -race -count=1 --run $(TEST_FUNC) ./integration_tests/... + +unittest: + go test -race -count=1 ./internal/... + +unittest-one: + go test -v -race -count=1 --run $(TEST_FUNC) ./internal/... + +GOLANGCI_LINT_VERSION := 1.60.1 + +lint: check-golangci-lint + golangci-lint run ./... + +check-golangci-lint: + @if ! command -v golangci-lint > /dev/null || ! golangci-lint version | grep -q "$(GOLANGCI_LINT_VERSION)"; then \ + echo "Required golangci-lint version $(GOLANGCI_LINT_VERSION) not found."; \ + echo "Please install golangci-lint version $(GOLANGCI_LINT_VERSION) with the following command:"; \ + echo "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.1"; \ + exit 1; \ + fi diff --git a/README.md b/README.md index 0fbc965..3e01521 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,28 @@ This repository hosts backend service implementation of the Playground. ## How to contribute -The Code Contribution Guidelines are published at [CONTRIBUTING.md](CONTRIBUTING.md); please read them before you start making any changes. This would allow us to have a consistent standard of coding practices and developer experience. +The code contribution guidelines are published at [CONTRIBUTING.md](CONTRIBUTING.md); please read them before you start making any changes. This would allow us to have a consistent standard of coding practices and developer experience. Contributors can join the [Discord Server](https://discord.gg/6r8uXWtXh7) for quick collaboration. +### Setting up this repository from source for development and contributions + +To run playground-mono for local development or running from source, you will need + +1. [Golang](https://go.dev/) +2. Any of the below supported platform environment: + 1. [Linux based environment](https://en.wikipedia.org/wiki/Comparison_of_Linux_distributions) + 2. [OSX (Darwin) based environment](https://en.wikipedia.org/wiki/MacOS) + 3. WSL under Windows +3. Install GoLangCI +``` +$ sudo su +$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /bin v1.60.1 +``` + +Steps to clone and run: +``` +$ git clone https://github.com/dicedb/playground-mono +$ cd playground-mono +$ go run main.go +``` diff --git a/main.go b/main.go index ed91c21..4170e5a 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "log" "net/http" "sync" @@ -32,7 +33,7 @@ func (s *HTTPServer) Run(ctx context.Context) error { go func() { defer wg.Done() log.Printf("Starting server at %s\n", s.httpServer.Addr) - if err := s.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { + if err := s.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { log.Fatalf("HTTP server error: %v", err) } }() @@ -56,6 +57,6 @@ func main() { // run the Http Server if err := httpServer.Run(ctx); err != nil { - log.Fatalf("Server failed: %v", err) + log.Printf("Server failed: %v\n", err) } } diff --git a/playground-mono b/playground-mono new file mode 100755 index 0000000..1d8bea9 Binary files /dev/null and b/playground-mono differ