Skip to content

Commit 82b4aba

Browse files
authored
Merge pull request #1 from codeforgood-org/claude/reorganize-enhance-repo-011CV6HngcZ3TexXNXQ3HjhZ
Enhance repo and code organization
2 parents 5b7fc68 + 663e380 commit 82b4aba

36 files changed

+2842
-80
lines changed

.air.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Air configuration file for hot reload during development
2+
# Install air: go install github.com/cosmtrek/air@latest
3+
4+
root = "."
5+
testdata_dir = "testdata"
6+
tmp_dir = "tmp"
7+
8+
[build]
9+
args_bin = []
10+
bin = "./tmp/main"
11+
cmd = "go build -o ./tmp/main ./cmd/api"
12+
delay = 1000
13+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
14+
exclude_file = []
15+
exclude_regex = ["_test.go"]
16+
exclude_unchanged = false
17+
follow_symlink = false
18+
full_bin = ""
19+
include_dir = []
20+
include_ext = ["go", "tpl", "tmpl", "html"]
21+
include_file = []
22+
kill_delay = "0s"
23+
log = "build-errors.log"
24+
poll = false
25+
poll_interval = 0
26+
rerun = false
27+
rerun_delay = 500
28+
send_interrupt = false
29+
stop_on_error = false
30+
31+
[color]
32+
app = ""
33+
build = "yellow"
34+
main = "magenta"
35+
runner = "green"
36+
watcher = "cyan"
37+
38+
[log]
39+
main_only = false
40+
time = false
41+
42+
[misc]
43+
clean_on_exit = false
44+
45+
[screen]
46+
clear_on_rebuild = false
47+
keep_scroll = true

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Server Configuration
2+
SERVER_PORT=8080
3+
4+
# Logging Configuration
5+
LOG_LEVEL=info

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.21'
22+
23+
- name: Cache Go modules
24+
uses: actions/cache@v3
25+
with:
26+
path: ~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
30+
31+
- name: Download dependencies
32+
run: go mod download
33+
34+
- name: Verify dependencies
35+
run: go mod verify
36+
37+
- name: Run go vet
38+
run: go vet ./...
39+
40+
- name: Run tests
41+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
42+
43+
- name: Upload coverage to Codecov
44+
uses: codecov/codecov-action@v3
45+
with:
46+
files: ./coverage.out
47+
flags: unittests
48+
name: codecov-umbrella
49+
50+
build:
51+
name: Build
52+
runs-on: ubuntu-latest
53+
needs: test
54+
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Set up Go
60+
uses: actions/setup-go@v5
61+
with:
62+
go-version: '1.21'
63+
64+
- name: Build
65+
run: go build -v ./cmd/api
66+
67+
- name: Build Docker image
68+
run: docker build -t book-api:latest .
69+
70+
lint:
71+
name: Lint
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Set up Go
79+
uses: actions/setup-go@v5
80+
with:
81+
go-version: '1.21'
82+
83+
- name: Run golangci-lint
84+
uses: golangci/golangci-lint-action@v3
85+
with:
86+
version: latest
87+
args: --timeout=5m

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
27+
# Build artifacts
28+
bin/
29+
tmp/
30+
31+
# Coverage files
32+
coverage.out
33+
coverage.html
34+
35+
# Air (live reload) logs
36+
build-errors.log

.golangci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# golangci-lint configuration file
2+
# See https://golangci-lint.run/usage/configuration/ for more options
3+
4+
run:
5+
timeout: 5m
6+
tests: true
7+
modules-download-mode: readonly
8+
9+
linters:
10+
enable:
11+
- errcheck
12+
- gosimple
13+
- govet
14+
- ineffassign
15+
- staticcheck
16+
- unused
17+
- gofmt
18+
- goimports
19+
- misspell
20+
- gocritic
21+
- revive
22+
23+
linters-settings:
24+
govet:
25+
check-shadowing: true
26+
gofmt:
27+
simplify: true
28+
goimports:
29+
local-prefixes: github.com/codeforgood-org/golang-book-api
30+
31+
issues:
32+
exclude-use-default: false
33+
max-same-issues: 0

CONTRIBUTING.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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

Comments
 (0)