From c576f6f0112624f12b5c3facc84f279c37d2613c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:09:22 +0000 Subject: [PATCH 1/5] Initial plan From d3e371df0811d3e155238512eb0b2b69559547ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:14:52 +0000 Subject: [PATCH 2/5] Initialize Go project with linters, pre-commit hooks, and CI/CD Co-authored-by: platonoff-dev <31926941+platonoff-dev@users.noreply.github.com> --- .editorconfig | 22 +++++++++++ .github/workflows/ci.yml | 72 ++++++++++++++++++++++++++++++++++ .gitignore | 15 ++++++- .golangci.yml | 84 +++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 27 +++++++++++++ CONTRIBUTING.md | 62 +++++++++++++++++++++++++++++ Makefile | 61 ++++++++++++++++++++++++++++ README.md | 85 +++++++++++++++++++++++++++++++++++++++- cmd/corekv/main.go | 7 ++++ go.mod | 3 ++ 10 files changed, 434 insertions(+), 4 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/ci.yml create mode 100644 .golangci.yml create mode 100644 .pre-commit-config.yaml create mode 100644 CONTRIBUTING.md create mode 100644 Makefile create mode 100644 cmd/corekv/main.go create mode 100644 go.mod diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dab2fcc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.go] +indent_style = tab +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.{json,md}] +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7f7525f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,72 @@ +name: CI + +on: + push: + branches: [ main, master, develop ] + pull_request: + branches: [ main, master, develop ] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ['1.21', '1.22'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Download dependencies + run: go mod download + + - name: Verify dependencies + run: go mod verify + + - name: Build + run: go build -v ./... + + - name: Run tests + run: go test -v -race -coverprofile=coverage.out ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.out + flags: unittests + name: codecov-umbrella + + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55.2 + args: --timeout=5m diff --git a/.gitignore b/.gitignore index aaadf73..38cc71f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,16 @@ go.work.sum .env # Editor/IDE -# .idea/ -# .vscode/ +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +Thumbs.db + +# Binary output +/corekv +/cmd/corekv/corekv diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..574055a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,84 @@ +run: + timeout: 5m + tests: true + modules-download-mode: readonly + +linters: + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - gofmt + - goimports + - misspell + - revive + - goconst + - gocyclo + - gosec + - unconvert + - unparam + - prealloc + - exportloopref + - bodyclose + - nilerr + - nolintlint + +linters-settings: + errcheck: + check-type-assertions: true + check-blank: true + + govet: + enable-all: true + disable: + - shadow + + gocyclo: + min-complexity: 15 + + revive: + confidence: 0.8 + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + + misspell: + locale: US + + goimports: + local-prefixes: github.com/platonoff-dev/corekv + +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + - path: _test\.go + linters: + - gosec + - errcheck diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..68b5328 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-merge-conflict + - id: check-case-conflict + - id: mixed-line-ending + + - repo: https://github.com/golangci/golangci-lint + rev: v1.55.2 + hooks: + - id: golangci-lint + args: [--fix] + + - repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-fmt + - id: go-imports + - id: go-mod-tidy + - id: go-vet + - id: go-build + - id: go-unit-tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..451fca9 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,62 @@ +# Contributing to CoreKV + +Thank you for considering contributing to CoreKV! This document outlines the process and guidelines for contributing. + +## Getting Started + +1. Fork the repository +2. Clone your fork: `git clone https://github.com/YOUR-USERNAME/corekv.git` +3. Create a new branch: `git checkout -b feature/my-feature` +4. Make your changes +5. Run tests: `make test` +6. Run linters: `make lint` +7. Commit your changes: `git commit -m "Add my feature"` +8. Push to your fork: `git push origin feature/my-feature` +9. Create a Pull Request + +## Development Guidelines + +### Code Style + +- Follow standard Go conventions and idioms +- Use `gofmt` and `goimports` for formatting (run `make fmt`) +- Keep functions small and focused +- Add comments for exported functions and types +- Write clear commit messages + +### Testing + +- Write tests for new features +- Ensure all tests pass before submitting a PR +- Aim for good test coverage +- Run `make test` to execute all tests + +### Linting + +- Run `make lint` before committing +- Address all linter warnings and errors +- Pre-commit hooks will run automatically if installed + +### Pre-commit Hooks + +Install pre-commit hooks to catch issues before committing: + +```bash +pip install pre-commit +make install-hooks +``` + +## Pull Request Process + +1. Update the README.md with details of changes if applicable +2. Ensure all tests pass and linters are happy +3. Update documentation as needed +4. The PR will be merged once reviewed and approved + +## Code Review + +All contributions require code review. We use GitHub pull requests for this purpose. + +## Questions? + +Feel free to open an issue for any questions or concerns! diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..54ac0d9 --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +.PHONY: help build test lint fmt clean install-tools install-hooks + +help: ## Display this help message + @echo "Available targets:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' + +build: ## Build the project + @echo "Building..." + go build -v ./... + +test: ## Run tests + @echo "Running tests..." + go test -v -race -coverprofile=coverage.out ./... + +test-coverage: test ## Run tests with coverage report + @echo "Generating coverage report..." + go tool cover -html=coverage.out -o coverage.html + @echo "Coverage report generated: coverage.html" + +lint: ## Run linters + @echo "Running linters..." + golangci-lint run ./... + +fmt: ## Format code + @echo "Formatting code..." + go fmt ./... + goimports -w -local github.com/platonoff-dev/corekv . + +vet: ## Run go vet + @echo "Running go vet..." + go vet ./... + +clean: ## Clean build artifacts + @echo "Cleaning..." + go clean + rm -f coverage.out coverage.html + +install-tools: ## Install development tools + @echo "Installing tools..." + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install golang.org/x/tools/cmd/goimports@latest + +install-hooks: ## Install pre-commit hooks + @echo "Installing pre-commit hooks..." + @if command -v pre-commit >/dev/null 2>&1; then \ + pre-commit install; \ + echo "Pre-commit hooks installed successfully"; \ + else \ + echo "pre-commit is not installed. Install it with: pip install pre-commit"; \ + exit 1; \ + fi + +mod-tidy: ## Tidy go.mod + @echo "Tidying go.mod..." + go mod tidy + +mod-verify: ## Verify dependencies + @echo "Verifying dependencies..." + go mod verify + +all: fmt lint test build ## Run all checks and build diff --git a/README.md b/README.md index 1cae5c3..dfc969e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,83 @@ -# corekv -Simple small persistent kv database +# CoreKV + +Simple small persistent key-value database written in Go. + +## Features + +- Lightweight and fast persistent key-value storage +- Simple API +- Thread-safe operations + +## Installation + +```bash +go get github.com/platonoff-dev/corekv +``` + +## Usage + +```bash +go run cmd/corekv/main.go +``` + +## Development + +### Prerequisites + +- Go 1.21 or higher +- golangci-lint (for linting) +- pre-commit (for pre-commit hooks) + +### Setup + +1. Clone the repository: +```bash +git clone https://github.com/platonoff-dev/corekv.git +cd corekv +``` + +2. Install development tools: +```bash +make install-tools +``` + +3. Install pre-commit hooks: +```bash +pip install pre-commit # if not already installed +make install-hooks +``` + +### Available Make Commands + +- `make build` - Build the project +- `make test` - Run tests +- `make test-coverage` - Run tests with coverage report +- `make lint` - Run linters +- `make fmt` - Format code +- `make clean` - Clean build artifacts +- `make all` - Run all checks and build + +## Project Structure + +``` +. +├── cmd/ +│ └── corekv/ # Main application +├── pkg/ # Public libraries +├── internal/ # Private application code +├── .github/ +│ └── workflows/ # GitHub Actions workflows +└── Makefile # Build and development tasks +``` + +## Contributing + +1. Fork the repository +2. Create your feature branch (`git checkout -b feature/amazing-feature`) +3. Commit your changes (`git commit -m 'Add some amazing feature'`) +4. Push to the branch (`git push origin feature/amazing-feature`) +5. Open a Pull Request + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/cmd/corekv/main.go b/cmd/corekv/main.go new file mode 100644 index 0000000..ddf3525 --- /dev/null +++ b/cmd/corekv/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("CoreKV - Simple small persistent key-value database") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9cb2058 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/platonoff-dev/corekv + +go 1.24.7 From 326bd7fc13f4d3b71151e5706b367e2d47113e7b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:18:22 +0000 Subject: [PATCH 3/5] Fix Go version consistency across configuration files Co-authored-by: platonoff-dev <31926941+platonoff-dev@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- README.md | 2 +- go.mod | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f7525f..c3dcab8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ['1.21', '1.22'] + go-version: ['1.22', '1.23'] steps: - name: Checkout code diff --git a/README.md b/README.md index dfc969e..270dddc 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ go run cmd/corekv/main.go ### Prerequisites -- Go 1.21 or higher +- Go 1.22 or higher - golangci-lint (for linting) - pre-commit (for pre-commit hooks) diff --git a/go.mod b/go.mod index 9cb2058..75bda4a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/platonoff-dev/corekv -go 1.24.7 +go 1.22 From cbff8d27a2d7899e5d212e7b124ad45aadd7c677 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:20:52 +0000 Subject: [PATCH 4/5] Add explicit GITHUB_TOKEN permissions to CI workflow Co-authored-by: platonoff-dev <31926941+platonoff-dev@users.noreply.github.com> --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3dcab8..9942ed1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,15 @@ on: pull_request: branches: [ main, master, develop ] +permissions: + contents: read + jobs: test: name: Test runs-on: ubuntu-latest + permissions: + contents: read strategy: matrix: go-version: ['1.22', '1.23'] @@ -55,6 +60,8 @@ jobs: lint: name: Lint runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout code From cbd0b9ab069feb3f8eefe1e5037f0afbd3cf0e2b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:23:09 +0000 Subject: [PATCH 5/5] Remove trailing spaces from golangci.yml Co-authored-by: platonoff-dev <31926941+platonoff-dev@users.noreply.github.com> --- .golangci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 574055a..8cd3b1d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,15 +30,15 @@ linters-settings: errcheck: check-type-assertions: true check-blank: true - + govet: enable-all: true disable: - shadow - + gocyclo: min-complexity: 15 - + revive: confidence: 0.8 rules: