eirka-get

Overview
eirka-get is the read-only API service for the Eirka imageboard system. It serves JSON responses for threads, posts, images, tags, and other imageboard features.
Features
- Caching System: Efficient Redis caching with circuit breaker pattern for resilience
- Singleflight Pattern: Prevents thundering herd problems by deduplicating concurrent requests
- JWT Authentication: Secure authentication for user-specific features
- Analytics: Request tracking and performance monitoring
- Efficient Pagination: Paginated results for large data sets
Architecture
The project follows a clean MVC architecture:
- Controllers: HTTP handlers that process requests and return JSON responses
- Models: Database interaction layer that fetches data from MySQL
- Middleware: Request processing components (caching, authentication, analytics)
- Config: Application configuration management
Cache System
The caching middleware implements Redis caching with several advanced features:
- Circuit Breaker Pattern: Automatically detects Redis failures and bypasses cache when Redis is experiencing issues
- Cache Key Management: Organizes cache keys by resource type
- Singleflight Pattern: Prevents duplicate database queries for concurrent requests to the same resource
- Intelligent Caching: Caches only appropriate endpoints and skips dynamic queries
Endpoints
The API provides the following main endpoints:
- Threads:
/thread/:imageboard/:thread/:page
- Posts:
/post/:imageboard/:post
- Images:
/image/:imageboard/:image
- Tags:
/tag/:imageboard/:tag, /tags/:imageboard
- Search:
/tagsearch/:imageboard/:search, /threadsearch/:imageboard/:search
- Favorites:
/favorites/:imageboard, /favorite/:imageboard/:thread, /favorited/:imageboard/:thread
- Directory:
/directory/:imageboard
- New Content:
/new/:imageboard
- Popular Content:
/popular/:imageboard
Installation
# Clone the repository
git clone https://github.com/eirka/eirka-get.git
# Install dependencies
go mod tidy
# Build the application
go build
Testing
# Run all tests
go test ./...
# Run specific tests
go test -v ./middleware -run TestCache
# Run tests with coverage
go test ./... -cover
Contributing
- Follow Go standard formatting (gofmt)
- Group imports in 3 blocks: standard lib, third-party, project-local
- Ensure tests pass before submitting changes
- Use error wrapping with
SetMeta() to provide context
License
See LICENSE file for details.