ReadGo is a Go code analysis tool that helps developers understand and navigate Go codebases. It provides functionality for analyzing Go source code, including type information, function signatures, and package dependencies.
- Project-wide code analysis
- Type information extraction
- Function signature analysis
- Package dependency tracking
- Interface implementation detection
- Code structure visualization
- Cache support for better performance
- Go 1.16 or later
- Make (optional, for using Makefile commands)
- golangci-lint (for code linting)
- Clone the repository:
git clone https://github.com/iamlongalong/readgo.git
cd readgo
- Install development tools:
make install-tools
- Build the project:
make build
// Initialize an analyzer
analyzer := readgo.NewAnalyzer()
// Analyze a file
result, err := analyzer.AnalyzeFile(context.Background(), "main.go")
// Analyze a package
result, err := analyzer.AnalyzePackage(context.Background(), "mypackage")
// Analyze an entire project
result, err := analyzer.AnalyzeProject(context.Background(), ".")
// Find a specific type
typeInfo, err := analyzer.FindType(context.Background(), "mypackage", "MyType")
// Find an interface
interfaceInfo, err := analyzer.FindInterface(context.Background(), "mypackage", "MyInterface")
The project includes a Makefile with common development commands:
# Show all available commands
make help
# Build the project
make build
# Run tests
make test
# Run code checks (format, vet, lint, test)
make check
# Run pre-commit checks
make pre-commit
# Format code
make fmt
# Clean build artifacts
make clean
analyzer := readgo.NewAnalyzer(
readgo.WithWorkDir("path/to/workspace"),
readgo.WithCacheTTL(time.Minute * 5),
)
The analyzer includes a caching system to improve performance:
- Default TTL: 5 minutes
- Cache can be disabled by setting TTL to 0
- Cache statistics available via
GetCacheStats()
.
├── analyzer.go # Main analyzer implementation
├── cache.go # Caching system
├── common.go # Common utilities
├── errors.go # Error definitions
├── options.go # Configuration options
├── reader.go # Source code reader
├── types.go # Type definitions
└── validator.go # Code validation
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Run tests and checks (
make pre-commit
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Make your changes
- Run
make fmt
to format code - Run
make check
to verify changes - Run
make pre-commit
before committing - Create pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- The Go team for the excellent
go/ast
andgo/types
packages - The community for feedback and contributions