Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
84 changes: 84 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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!
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Loading