https://github.com/mateusfigmelo/go_by_examples
Go By Example
https://github.com/mateusfigmelo/go_by_examples
go gobyexample golang
Last synced: 11 months ago
JSON representation
Go By Example
- Host: GitHub
- URL: https://github.com/mateusfigmelo/go_by_examples
- Owner: mateusfigmelo
- License: mit
- Created: 2025-05-03T14:35:19.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-03T21:38:11.000Z (about 1 year ago)
- Last Synced: 2025-07-06T03:02:44.490Z (11 months ago)
- Topics: go, gobyexample, golang
- Language: Go
- Homepage:
- Size: 127 KB
- Stars: 26
- Watchers: 1
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Go By Examples
[](https://golang.org/dl/)
[](LICENSE)
[](https://github.com/mateusfigmelo/go_by_examples/pulls)
[](https://github.com/mateusfigmelo/go_by_examples/stargazers)
[](https://pkg.go.dev/golang.org/x/example)
[](https://goreportcard.com/report/github.com/mateusfigmelo/go_by_examples)
[](https://github.com/mateusfigmelo/go_by_examples/commits/main)
[](https://github.com/mateusfigmelo/go_by_examples)
A comprehensive collection of Go programming examples
Learn Go by example: from basic concepts to advanced patterns and best practices
## Examples
1. [Hello World](./examples/01-hello-world) - Basic program structure
2. [Data Types](./examples/02-data-types) - Types, variables, and constants
3. [Control Structures](./examples/03-control-structures) - Flow control and branching
4. [Collections](./examples/04-collections) - Arrays, slices, and maps
5. [Functions](./examples/05-functions) - Function declarations and usage
6. [Types and Pointers](./examples/06-types-and-pointers) - Memory management
7. [Structs and Interfaces](./examples/07-structs-and-interfaces) - Custom types and abstraction
8. [Generics and Embedding](./examples/08-generics-and-embedding) - Generic programming and composition
9. [Error Handling](./examples/09-error-handling) - Error types and handling
10. [Concurrency](./examples/10-concurrency) - Goroutines and basic concurrency
11. [Advanced Channels](./examples/11-advanced-channels) - Channel patterns and usage
12. [Worker Pools](./examples/12-worker-pools) - Concurrent worker patterns
13. [Sync Primitives](./examples/13-sync-primitives) - Mutexes and synchronization
14. [Sorting](./examples/14-sorting) - Sorting algorithms and interfaces
15. [Panic, Defer, Recover](./examples/15-panic-defer-recover) - Error flow control
16. [Strings and Templates](./examples/16-strings-and-templates) - String manipulation
17. [JSON and XML](./examples/17-json-xml) - Data serialization
18. [Time Handling](./examples/18-time-handling) - Time operations
19. [Parsing and Random](./examples/19-parsing-and-random) - Text parsing and randomization
20. [Hashes and Encoding](./examples/20-hashes-and-encoding) - Cryptography basics
21. [File Operations](./examples/21-file-operations) - File system handling
22. [File Utilities](./examples/22-file-utilities) - Advanced file operations
23. [Testing and Benchmarking](./examples/23-testing-benchmarking) - Advanced testing
24. [CLI](./examples/24-cli) - Command-line interfaces
25. [Environment and Logging](./examples/25-env-and-logging) - Configuration and logs
26. [HTTP Client and Server](./examples/26-http) - HTTP client/server
27. [Context and Processes](./examples/27-context-and-processes) - Process management
28. [Signals and Exit](./examples/28-signals-and-exit) - Signal handling
## Prerequisites
- Go 1.21 or higher (some examples use newer features)
- Basic understanding of Go programming concepts
- Text editor or IDE
- Terminal/Command Prompt
## Running Examples
Each example directory contains:
- Source code files (`.go`)
- README with explanations and instructions
- Tests where applicable
- Any necessary resource files
To run an example:
```bash
cd examples/
go run main.go
```
## Testing
Each example includes tests that demonstrate proper usage and validate functionality. We use Go's built-in testing framework with some extended features.
### Running Tests
You can run tests using our Go test runner:
```bash
# 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
```
### Test Coverage
Coverage reports are generated in HTML format when running tests with the `-c` or `--coverage` flag. These reports are saved in the `coverage/` directory.
## Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-example`)
3. Make your changes and add appropriate tests
4. Ensure all tests pass (`go run main.go`)
5. Commit your changes (`git commit -m 'Add a new example'`)
6. Push to the branch (`git push origin feature/amazing-example`)
7. Create a Pull Request
## Best Practices
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
### Testing 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
## License
This project is licensed under the MIT License - see the LICENSE file for details.