This directory contains practical examples demonstrating how to use the city-timezones-go library.
examples/
├── basic/ # Basic usage examples
├── advanced/ # Advanced features and patterns
└── cli/ # Command-line tool usage examples
Simple examples showing core functionality:
# Run from project root
cd examples/basic
go run main.goThis demonstrates:
- Looking up cities by exact name
- Partial matching searches
- ISO code lookups
- Handling empty results
- Getting all cities
Advanced patterns including concurrency and caching:
# Run from project root
cd examples/advanced
go run main.goThis demonstrates:
- Custom search options (case-sensitive, exact match)
- Thread-safe concurrent lookups
- Cache performance optimization
- Proper error handling patterns
Command-line tool usage examples:
# Run from project root
cd examples/cli
./usage.shThis demonstrates:
- Simple city lookups
- Partial searches
- ISO code filtering
- Timezone filtering
- JSON output format
- Batch lookups
If you're new to the library, start with the basic examples:
- First: Run
examples/basic/main.goto understand core features - Then: Run
examples/advanced/main.goto see advanced patterns - Finally: Try
examples/cli/usage.shto explore CLI options
All examples can be run directly with go run, but you can also build them:
# Build basic example
cd examples/basic
go build -o basic-demo main.go
./basic-demo
# Build advanced example
cd examples/advanced
go build -o advanced-demo main.go
./advanced-demo=== City Timezones - Basic Examples ===
1. Looking up Chicago:
City: Chicago, Illinois
Country: United States of America (US)
Timezone: America/Chicago
Coordinates: 41.8500, -87.6500
Population: 2695598
...
=== City Timezones - Advanced Examples ===
1. Advanced Search with Options:
Case-sensitive search for 'Chicago': found 1 results
Exact match search for 'chicago': found 1 results
2. Concurrent Lookups (Thread Safety Demo):
✓ Tokyo -> Asia/Tokyo
✓ London -> Europe/London
✓ New York -> America/New_York
...
To use these patterns in your own project:
import "github.com/richoandika/city-timezones-go/pkg/citytimezones"
// Copy patterns from examples/basic or examples/advanced
cities, err := citytimezones.LookupViaCity("YourCity")
if err != nil {
// Handle error
}
// Use results- See the main README for full documentation
- Check the API documentation for detailed function reference
- Review Contributing Guide if you want to add more examples
Have a useful example? We'd love to include it! Please:
- Add your example to the appropriate directory
- Update this README with a description
- Ensure it follows Go best practices
- Test that it runs without errors
- Submit a pull request
Examples we'd love to see:
- Web API integration
- Database storage patterns
- Custom caching strategies
- Performance optimization techniques
- Real-world application use cases