|
| 1 | +# Contributing to Book API |
| 2 | + |
| 3 | +Thank you for your interest in contributing to the Book API project! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Code of Conduct |
| 6 | + |
| 7 | +By participating in this project, you agree to maintain a respectful and inclusive environment for everyone. |
| 8 | + |
| 9 | +## How to Contribute |
| 10 | + |
| 11 | +### Reporting Bugs |
| 12 | + |
| 13 | +If you find a bug, please create an issue with: |
| 14 | +- A clear, descriptive title |
| 15 | +- Steps to reproduce the issue |
| 16 | +- Expected behavior |
| 17 | +- Actual behavior |
| 18 | +- Your environment (OS, Go version, etc.) |
| 19 | + |
| 20 | +### Suggesting Enhancements |
| 21 | + |
| 22 | +Enhancement suggestions are welcome! Please create an issue with: |
| 23 | +- A clear, descriptive title |
| 24 | +- Detailed description of the proposed feature |
| 25 | +- Rationale for why this enhancement would be useful |
| 26 | +- Possible implementation approach (optional) |
| 27 | + |
| 28 | +### Pull Requests |
| 29 | + |
| 30 | +1. **Fork the repository** and create your branch from `main` |
| 31 | + ```bash |
| 32 | + git checkout -b feature/amazing-feature |
| 33 | + ``` |
| 34 | + |
| 35 | +2. **Make your changes** |
| 36 | + - Follow the project's coding style |
| 37 | + - Write clear, concise commit messages |
| 38 | + - Add tests for new functionality |
| 39 | + - Update documentation as needed |
| 40 | + |
| 41 | +3. **Test your changes** |
| 42 | + ```bash |
| 43 | + make test |
| 44 | + make lint |
| 45 | + ``` |
| 46 | + |
| 47 | +4. **Commit your changes** |
| 48 | + ```bash |
| 49 | + git commit -m "Add amazing feature" |
| 50 | + ``` |
| 51 | + |
| 52 | +5. **Push to your fork** |
| 53 | + ```bash |
| 54 | + git push origin feature/amazing-feature |
| 55 | + ``` |
| 56 | + |
| 57 | +6. **Open a Pull Request** |
| 58 | + - Provide a clear description of the changes |
| 59 | + - Reference any related issues |
| 60 | + - Ensure all tests pass |
| 61 | + - Wait for review |
| 62 | + |
| 63 | +## Development Setup |
| 64 | + |
| 65 | +### Prerequisites |
| 66 | + |
| 67 | +- Go 1.21 or higher |
| 68 | +- Git |
| 69 | +- Make (optional but recommended) |
| 70 | + |
| 71 | +### Setup Steps |
| 72 | + |
| 73 | +1. Clone your fork: |
| 74 | + ```bash |
| 75 | + git clone https://github.com/YOUR_USERNAME/golang-book-api.git |
| 76 | + cd golang-book-api |
| 77 | + ``` |
| 78 | + |
| 79 | +2. Install dependencies: |
| 80 | + ```bash |
| 81 | + go mod download |
| 82 | + ``` |
| 83 | + |
| 84 | +3. Run tests: |
| 85 | + ```bash |
| 86 | + make test |
| 87 | + ``` |
| 88 | + |
| 89 | +4. Run the application: |
| 90 | + ```bash |
| 91 | + make run |
| 92 | + ``` |
| 93 | + |
| 94 | +## Coding Standards |
| 95 | + |
| 96 | +### Go Style Guide |
| 97 | + |
| 98 | +- Follow the official [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments) |
| 99 | +- Use `gofmt` to format your code |
| 100 | +- Run `go vet` to check for common mistakes |
| 101 | +- Use meaningful variable and function names |
| 102 | + |
| 103 | +### Project Structure |
| 104 | + |
| 105 | +- **`cmd/`** - Application entry points |
| 106 | +- **`internal/`** - Private application code |
| 107 | +- **`pkg/`** - Public libraries |
| 108 | +- Keep packages focused and cohesive |
| 109 | +- Use interfaces for dependencies |
| 110 | + |
| 111 | +### Testing |
| 112 | + |
| 113 | +- Write unit tests for all new functionality |
| 114 | +- Aim for high test coverage |
| 115 | +- Use table-driven tests where appropriate |
| 116 | +- Mock external dependencies |
| 117 | + |
| 118 | +Example test: |
| 119 | +```go |
| 120 | +func TestBookValidate(t *testing.T) { |
| 121 | + tests := []struct { |
| 122 | + name string |
| 123 | + book Book |
| 124 | + wantErr bool |
| 125 | + }{ |
| 126 | + // test cases |
| 127 | + } |
| 128 | + |
| 129 | + for _, tt := range tests { |
| 130 | + t.Run(tt.name, func(t *testing.T) { |
| 131 | + // test implementation |
| 132 | + }) |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +### Documentation |
| 138 | + |
| 139 | +- Add godoc comments for public functions and types |
| 140 | +- Update README.md for significant changes |
| 141 | +- Include examples for complex functionality |
| 142 | + |
| 143 | +### Commit Messages |
| 144 | + |
| 145 | +Write clear commit messages: |
| 146 | +- Use present tense ("Add feature" not "Added feature") |
| 147 | +- Keep the first line under 50 characters |
| 148 | +- Add detailed description after a blank line if needed |
| 149 | + |
| 150 | +Good examples: |
| 151 | +``` |
| 152 | +Add book validation logic |
| 153 | +
|
| 154 | +Implement validation for book title and author fields. |
| 155 | +Returns appropriate error messages for invalid input. |
| 156 | +``` |
| 157 | + |
| 158 | +## Testing Guidelines |
| 159 | + |
| 160 | +### Running Tests |
| 161 | + |
| 162 | +```bash |
| 163 | +# Run all tests |
| 164 | +make test |
| 165 | + |
| 166 | +# Run tests with coverage |
| 167 | +make test-cover |
| 168 | + |
| 169 | +# Run specific package tests |
| 170 | +go test ./internal/storage/... |
| 171 | +``` |
| 172 | + |
| 173 | +### Writing Tests |
| 174 | + |
| 175 | +- Test public APIs |
| 176 | +- Test edge cases and error conditions |
| 177 | +- Use descriptive test names |
| 178 | +- Keep tests simple and focused |
| 179 | + |
| 180 | +## Review Process |
| 181 | + |
| 182 | +1. All pull requests require review before merging |
| 183 | +2. Address reviewer feedback |
| 184 | +3. Keep discussions professional and constructive |
| 185 | +4. CI checks must pass |
| 186 | + |
| 187 | +## Questions? |
| 188 | + |
| 189 | +If you have questions about contributing, feel free to: |
| 190 | +- Open an issue for discussion |
| 191 | +- Reach out to the maintainers |
| 192 | + |
| 193 | +Thank you for contributing! |
0 commit comments