|
| 1 | +# Contributing to quickwit-go |
| 2 | + |
| 3 | +Thank you for your interest in contributing to quickwit-go! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +1. Fork the repository |
| 8 | +2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/quickwit-go.git` |
| 9 | +3. Create a new branch: `git checkout -b feature/your-feature-name` |
| 10 | +4. Make your changes |
| 11 | +5. Run tests: `go test -v ./...` |
| 12 | +6. Run linter: `golangci-lint run` |
| 13 | +7. Commit your changes: `git commit -am 'Add some feature'` |
| 14 | +8. Push to the branch: `git push origin feature/your-feature-name` |
| 15 | +9. Create a Pull Request |
| 16 | + |
| 17 | +## Development Setup |
| 18 | + |
| 19 | +### Prerequisites |
| 20 | + |
| 21 | +- Go 1.24 or later |
| 22 | +- Docker (for running integration tests) |
| 23 | +- golangci-lint (for linting) |
| 24 | + |
| 25 | +### Install Dependencies |
| 26 | + |
| 27 | +```bash |
| 28 | +go mod download |
| 29 | +``` |
| 30 | + |
| 31 | +### Running Tests |
| 32 | + |
| 33 | +```bash |
| 34 | +# Run all tests |
| 35 | +go test -v ./... |
| 36 | + |
| 37 | +# Run tests with race detection |
| 38 | +go test -v -race ./... |
| 39 | + |
| 40 | +# Run tests with coverage |
| 41 | +go test -v -race -coverprofile=coverage.out ./... |
| 42 | + |
| 43 | +# Run tests with container logs |
| 44 | +CONTAINER_LOG=true go test -v ./... |
| 45 | +``` |
| 46 | + |
| 47 | +### Running Linter |
| 48 | + |
| 49 | +```bash |
| 50 | +# Install golangci-lint |
| 51 | +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| 52 | + |
| 53 | +# Run linter |
| 54 | +golangci-lint run |
| 55 | + |
| 56 | +# Run linter with auto-fix |
| 57 | +golangci-lint run --fix |
| 58 | +``` |
| 59 | + |
| 60 | +## Code Guidelines |
| 61 | + |
| 62 | +### Go Style |
| 63 | + |
| 64 | +- Follow the [Effective Go](https://golang.org/doc/effective_go) guidelines |
| 65 | +- Use `gofmt` to format your code |
| 66 | +- Add comments to exported functions, types, and constants |
| 67 | +- Keep functions small and focused |
| 68 | +- Use meaningful variable and function names |
| 69 | + |
| 70 | +### Testing |
| 71 | + |
| 72 | +- Write tests for all new features |
| 73 | +- Maintain or improve code coverage |
| 74 | +- Use table-driven tests where appropriate |
| 75 | +- Use Testcontainers for integration tests |
| 76 | +- Clean up resources in tests (use `defer` or `t.Cleanup()`) |
| 77 | + |
| 78 | +### Commits |
| 79 | + |
| 80 | +- Write clear, concise commit messages |
| 81 | +- Use conventional commit format: |
| 82 | + - `feat: add new feature` |
| 83 | + - `fix: resolve bug` |
| 84 | + - `docs: update documentation` |
| 85 | + - `test: add tests` |
| 86 | + - `refactor: refactor code` |
| 87 | + - `chore: update dependencies` |
| 88 | + |
| 89 | +### Pull Requests |
| 90 | + |
| 91 | +- Fill out the Pull Request template |
| 92 | +- Ensure all CI checks pass |
| 93 | +- Request review from maintainers |
| 94 | +- Address review comments promptly |
| 95 | +- Keep PRs focused and reasonably sized |
| 96 | + |
| 97 | +## Project Structure |
| 98 | + |
| 99 | +``` |
| 100 | +quickwit-go/ |
| 101 | +├── .github/ # GitHub configuration |
| 102 | +│ ├── workflows/ # GitHub Actions workflows |
| 103 | +│ ├── CI.md # CI documentation |
| 104 | +│ ├── CONTRIBUTING.md # This file |
| 105 | +│ ├── PULL_REQUEST_TEMPLATE.md |
| 106 | +│ └── dependabot.yml # Dependabot configuration |
| 107 | +├── model_*.go # Model definitions (one per file) |
| 108 | +├── client.go # Client implementation |
| 109 | +├── client_test.go # Client tests |
| 110 | +├── builder.go # Client builder |
| 111 | +├── constants.go # Constants |
| 112 | +├── testcontainer.go # Testcontainer setup |
| 113 | +├── go.mod # Go module definition |
| 114 | +├── go.sum # Go module checksums |
| 115 | +├── README.md # Project README |
| 116 | +├── TESTING.md # Testing documentation |
| 117 | +├── LICENSE # MIT License |
| 118 | +└── .golangci.yml # Linter configuration |
| 119 | +``` |
| 120 | + |
| 121 | +## Adding New Features |
| 122 | + |
| 123 | +When adding new features: |
| 124 | + |
| 125 | +1. **Add the method to the `Client` interface** in `client.go` |
| 126 | +2. **Implement the method** in `client.go` |
| 127 | +3. **Add models** if needed (create new `model_*.go` files) |
| 128 | +4. **Write tests** in `client_test.go` |
| 129 | +5. **Update documentation** in README.md and TESTING.md |
| 130 | +6. **Run tests and linter** to ensure everything works |
| 131 | + |
| 132 | +### Example: Adding a New Endpoint |
| 133 | + |
| 134 | +```go |
| 135 | +// 1. Add to Client interface |
| 136 | +type Client interface { |
| 137 | + // ... existing methods |
| 138 | + NewMethod(ctx context.Context, param string) (*Response, error) |
| 139 | +} |
| 140 | + |
| 141 | +// 2. Implement the method |
| 142 | +func (c *client) NewMethod(ctx context.Context, param string) (*Response, error) { |
| 143 | + req, err := http.NewRequestWithContext( |
| 144 | + ctx, |
| 145 | + "GET", |
| 146 | + fmt.Sprintf("%s/api/v1/new-endpoint?param=%s", c.endpoint, param), |
| 147 | + nil, |
| 148 | + ) |
| 149 | + if err != nil { |
| 150 | + return nil, err |
| 151 | + } |
| 152 | + |
| 153 | + for _, interceptor := range c.interceptors { |
| 154 | + interceptor(req) |
| 155 | + } |
| 156 | + |
| 157 | + return Request[Response](c.log, req) |
| 158 | +} |
| 159 | + |
| 160 | +// 3. Add tests |
| 161 | +func TestClient(t *testing.T) { |
| 162 | + // ... setup |
| 163 | + |
| 164 | + t.Run("New Method", func(t *testing.T) { |
| 165 | + result, err := client.NewMethod(ctx, "test-param") |
| 166 | + require.NoError(t, err) |
| 167 | + assert.NotNil(t, result) |
| 168 | + }) |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +## Reporting Issues |
| 173 | + |
| 174 | +- Use the GitHub issue tracker |
| 175 | +- Check if the issue already exists |
| 176 | +- Provide a clear description |
| 177 | +- Include steps to reproduce |
| 178 | +- Include Go version and OS information |
| 179 | +- Include relevant logs and error messages |
| 180 | + |
| 181 | +## Questions? |
| 182 | + |
| 183 | +- Open a GitHub issue with the "question" label |
| 184 | +- Check existing issues and documentation first |
| 185 | + |
| 186 | +## License |
| 187 | + |
| 188 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
0 commit comments