- Hello World - Basic program structure
- Data Types - Types, variables, and constants
- Control Structures - Flow control and branching
- Collections - Arrays, slices, and maps
- Functions - Function declarations and usage
- Types and Pointers - Memory management
- Structs and Interfaces - Custom types and abstraction
- Generics and Embedding - Generic programming and composition
- Error Handling - Error types and handling
- Concurrency - Goroutines and basic concurrency
- Advanced Channels - Channel patterns and usage
- Worker Pools - Concurrent worker patterns
- Sync Primitives - Mutexes and synchronization
- Sorting - Sorting algorithms and interfaces
- Panic, Defer, Recover - Error flow control
- Strings and Templates - String manipulation
- JSON and XML - Data serialization
- Time Handling - Time operations
- Parsing and Random - Text parsing and randomization
- Hashes and Encoding - Cryptography basics
- File Operations - File system handling
- File Utilities - Advanced file operations
- Testing and Benchmarking - Advanced testing
- CLI - Command-line interfaces
- Environment and Logging - Configuration and logs
- HTTP Client and Server - HTTP client/server
- Context and Processes - Process management
- Signals and Exit - Signal handling
- Go 1.21 or higher (some examples use newer features)
- Basic understanding of Go programming concepts
- Text editor or IDE
- Terminal/Command Prompt
Each example directory contains:
- Source code files (
.go
) - README with explanations and instructions
- Tests where applicable
- Any necessary resource files
To run an example:
cd examples/<example-directory>
go run main.go
Each example includes tests that demonstrate proper usage and validate functionality. We use Go's built-in testing framework with some extended features.
You can run tests using our Go test runner:
# Run all tests
go run main.go
# Run tests for a specific example
go run main.go 12-worker-pools
# Run tests with coverage
go run main.go -c
# Get verbose test output
go run main.go -v
# See all options
go run main.go -h
Coverage reports are generated in HTML format when running tests with the -c
or --coverage
flag. These reports are saved in the coverage/
directory.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-example
) - Make your changes and add appropriate tests
- Ensure all tests pass (
go run main.go
) - Commit your changes (
git commit -m 'Add a new example'
) - Push to the branch (
git push origin feature/amazing-example
) - Create a Pull Request
Each example follows these principles:
- Clear and documented code
- Proper error handling
- Comprehensive unit tests
- Table-driven testing where appropriate
- Consistent formatting (using
go fmt
) - Idiomatic Go patterns
- Performance considerations
- Security best practices
- Write tests for all exported functions
- Use table-driven tests for multiple scenarios
- Aim for high code coverage (at least 80%)
- Test both happy paths and error cases
- Keep tests independent and idempotent
- Use mocks or stubs for external dependencies
- Include benchmarks for performance-critical code
- Write clear failure messages
This project is licensed under the MIT License - see the LICENSE file for details.