File Processing API Specification
Defines a Go API for secure file processing with validation, error handling, and optional performance optimizations.
What this file does
Defines a Go API for secure file processing with validation, error handling, and optional performance optimizations.
When to use it
- Implementing file processing with security checks
- Standardizing file validation and error handling across services
- Designing batch file processing with performance constraints
- Creating an API spec for file operations in Go projects
Assumes this stack
File Processing API Specification
Overview
This API provides secure file processing capabilities with validation, error handling, and optional performance optimizations.
Core Functions
ProcessFile Function
- Name:
ProcessFile - Parameters:
filePath string, options ProcessOptions - Return:
*ProcessResult, error - Description: Processes a file with the given options and returns results
- Required Error Handling:
- MUST return error if file doesn't exist
- MUST detect and reject corrupted files
- MUST validate file path to prevent directory traversal attacks
- Security: File paths must be sanitized to prevent path traversal vulnerabilities
ValidateFileSize Function
- Name:
ValidateFileSize - Parameters:
filePath string, maxSizeBytes int64 - Return:
bool, error - Description: Validates that file size is within limits
- Required: Must return error for files exceeding maxSizeBytes
- Recommended: Should log validation attempts for audit purposes
ProcessBatch Function
- Name:
ProcessBatch - Parameters:
filePaths []string, options ProcessOptions - Return:
[]ProcessResult, error - Description: Processes multiple files efficiently
- Required: Must process files in the order provided
- Performance: Should use efficient algorithms to avoid O(n²) complexity
- Error Handling: Must use standard error message format: "failed to process file [filename]: [reason]"
Data Structures
ProcessOptions Struct
- Required Fields:
Timeout time.Duration- Maximum processing time per fileValidateIntegrity bool- Whether to perform integrity checks
- Optional Fields:
MaxRetries int- Number of retry attempts (default behavior unspecified)EnableCaching bool- Enable result caching for performance
ProcessResult Struct
- Required Fields:
FilePath string- Original file pathSuccess bool- Whether processing succeededProcessedAt time.Time- When processing completed
- Optional Fields:
CacheHit bool- Whether result came from cacheProcessingDuration time.Duration- Time taken to process
Error Handling Requirements
- File corruption must be detected and cause function failure
- Missing files must return appropriate error messages
- Security violations (path traversal) must be prevented
- All processing errors should be logged for debugging
Performance Recommendations
- Large batch operations should be optimized for memory usage
- Caching mechanisms may be implemented for frequently accessed files
- File size validation should be performed before processing to save resources
Logging Requirements
- Important operations should be logged with appropriate detail level
- Security events (rejected paths) should be logged for audit trails
What's inside
3 function specs, 2 struct definitions, error handling, performance, and logging requirements.
Change this for your project
- Replace
rejot-dev/semcheckwith your own repository path - Adjust
ProcessOptionsandProcessResultfields to match your domain - Modify error message format
"failed to process file [filename]: [reason]"if needed
Where it goes
Keep in docs/ or alongside the feature. Agents read it to implement against a defined contract.
Worth borrowing
- Separating required vs recommended behaviors in specs
- Explicit security requirements like path traversal prevention
- Standardized error message format for consistency
Related Documents
GPU Selection Guide for Large Language Models (LLMs)
Guides GPU selection for LLM inference, fine-tuning, and training by mapping model sizes, precision levels, and budgets to VRAM requirements.
Community AI Agent Skills Discovery Sources
Catalogs 50+ platforms, repositories, directories, and communities for discovering and sharing AI agent skills across multiple coding tools.
ReleaseKit - Technical Requirements Document
Specifies a Go library and CLI for release automation with conventional commit parsing, validation checks, and workflow orchestration.
api_llm Specification
Defines a workspace of thin HTTP API clients for major LLM providers with no abstraction layer and explicit developer control.