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..9942ed1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +name: CI + +on: + push: + branches: [ main, master, develop ] + 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'] + + 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 + permissions: + contents: read + + 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..8cd3b1d --- /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..270dddc 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.22 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..75bda4a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/platonoff-dev/corekv + +go 1.22