Go Gin Framework

Category: backend October 19, 2025

Agent instructions for Go REST API development with Gin framework

golangginrestapi
# Go Gin Framework Development

## Setup

- Initialize module: `go mod init <module-name>`
- Install dependencies: `go mod tidy`
- Run: `go run main.go`
- Build: `go build -o app`
- Test: `go test ./...`

## Project Structure

project/ ├── main.go ├── handlers/ # HTTP handlers ├── models/ # Data models ├── routes/ # Route definitions ├── middleware/ # Middleware functions └── utils/ # Helper functions


## Code Style

- Follow Go conventions (gofmt, golint)
- Use dependency injection
- Handle errors explicitly
- Use context for request-scoped values
- Keep handlers thin

## Testing

- Unit tests for handlers and services
- Use httptest for HTTP testing
- Mock external dependencies
- Run `go test -v ./...`
- Check coverage: `go test -cover ./...`

## Best Practices

- Use Gin middleware for cross-cutting concerns
- Implement proper error handling
- Use struct tags for JSON binding
- Validate input with binding
- Use goroutines carefully