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
47 changes: 47 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Air configuration file for hot reload during development
# Install air: go install github.com/cosmtrek/air@latest

root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/api"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Server Configuration
SERVER_PORT=8080

# Logging Configuration
LOG_LEVEL=info
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download dependencies
run: go mod download

- name: Verify dependencies
run: go mod verify

- name: Run go vet
run: go vet ./...

- name: Run tests
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.out
flags: unittests
name: codecov-umbrella

build:
name: Build
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Build
run: go build -v ./cmd/api

- name: Build Docker image
run: docker build -t book-api:latest .

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ go.work.sum

# env file
.env

# Build artifacts
bin/
tmp/

# Coverage files
coverage.out
coverage.html

# Air (live reload) logs
build-errors.log
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# golangci-lint configuration file
# See https://golangci-lint.run/usage/configuration/ for more options

run:
timeout: 5m
tests: true
modules-download-mode: readonly

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- goimports
- misspell
- gocritic
- revive

linters-settings:
govet:
check-shadowing: true
gofmt:
simplify: true
goimports:
local-prefixes: github.com/codeforgood-org/golang-book-api

issues:
exclude-use-default: false
max-same-issues: 0
193 changes: 193 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Contributing to Book API

Thank you for your interest in contributing to the Book API project! This document provides guidelines and instructions for contributing.

## Code of Conduct

By participating in this project, you agree to maintain a respectful and inclusive environment for everyone.

## How to Contribute

### Reporting Bugs

If you find a bug, please create an issue with:
- A clear, descriptive title
- Steps to reproduce the issue
- Expected behavior
- Actual behavior
- Your environment (OS, Go version, etc.)

### Suggesting Enhancements

Enhancement suggestions are welcome! Please create an issue with:
- A clear, descriptive title
- Detailed description of the proposed feature
- Rationale for why this enhancement would be useful
- Possible implementation approach (optional)

### Pull Requests

1. **Fork the repository** and create your branch from `main`
```bash
git checkout -b feature/amazing-feature
```

2. **Make your changes**
- Follow the project's coding style
- Write clear, concise commit messages
- Add tests for new functionality
- Update documentation as needed

3. **Test your changes**
```bash
make test
make lint
```

4. **Commit your changes**
```bash
git commit -m "Add amazing feature"
```

5. **Push to your fork**
```bash
git push origin feature/amazing-feature
```

6. **Open a Pull Request**
- Provide a clear description of the changes
- Reference any related issues
- Ensure all tests pass
- Wait for review

## Development Setup

### Prerequisites

- Go 1.21 or higher
- Git
- Make (optional but recommended)

### Setup Steps

1. Clone your fork:
```bash
git clone https://github.com/YOUR_USERNAME/golang-book-api.git
cd golang-book-api
```

2. Install dependencies:
```bash
go mod download
```

3. Run tests:
```bash
make test
```

4. Run the application:
```bash
make run
```

## Coding Standards

### Go Style Guide

- Follow the official [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
- Use `gofmt` to format your code
- Run `go vet` to check for common mistakes
- Use meaningful variable and function names

### Project Structure

- **`cmd/`** - Application entry points
- **`internal/`** - Private application code
- **`pkg/`** - Public libraries
- Keep packages focused and cohesive
- Use interfaces for dependencies

### Testing

- Write unit tests for all new functionality
- Aim for high test coverage
- Use table-driven tests where appropriate
- Mock external dependencies

Example test:
```go
func TestBookValidate(t *testing.T) {
tests := []struct {
name string
book Book
wantErr bool
}{
// test cases
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// test implementation
})
}
}
```

### Documentation

- Add godoc comments for public functions and types
- Update README.md for significant changes
- Include examples for complex functionality

### Commit Messages

Write clear commit messages:
- Use present tense ("Add feature" not "Added feature")
- Keep the first line under 50 characters
- Add detailed description after a blank line if needed

Good examples:
```
Add book validation logic

Implement validation for book title and author fields.
Returns appropriate error messages for invalid input.
```

## Testing Guidelines

### Running Tests

```bash
# Run all tests
make test

# Run tests with coverage
make test-cover

# Run specific package tests
go test ./internal/storage/...
```

### Writing Tests

- Test public APIs
- Test edge cases and error conditions
- Use descriptive test names
- Keep tests simple and focused

## Review Process

1. All pull requests require review before merging
2. Address reviewer feedback
3. Keep discussions professional and constructive
4. CI checks must pass

## Questions?

If you have questions about contributing, feel free to:
- Open an issue for discussion
- Reach out to the maintainers

Thank you for contributing!
Loading
Loading