Go Framework Support
RE-cue provides comprehensive support for analyzing Go web applications built with popular frameworks.
Supported Frameworks
Gin (github.com/gin-gonic/gin)
Framework ID: go_gin
Gin is a high-performance HTTP web framework written in Go, featuring a Martini-like API with better performance.
Capabilities:
- ✅ REST API endpoint discovery
- ✅ Route parameter detection
- ✅ Middleware and authentication detection
- ✅ Struct-based model discovery
- ✅ Service layer identification
- ✅ Actor extraction from roles
- ✅ System boundary mapping
- ✅ Use case generation
Example Detection:
// go.mod
require (
github.com/gin-gonic/gin v1.9.1
)
// main.go
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/api/users", GetUsers)
r.POST("/api/users", authMiddleware, CreateUser)
r.Run(":8080")
}
Echo (github.com/labstack/echo)
Framework ID: go_echo
Echo is a high-performance, extensible, minimalist Go web framework with a focus on developer experience.
Capabilities:
- ✅ REST API endpoint discovery
- ✅ Route parameter detection
- ✅ Middleware and authentication detection
- ✅ Struct-based model discovery
- ✅ Service layer identification
- ✅ Actor extraction from roles
- ✅ System boundary mapping
- ✅ Use case generation
Example Detection:
// go.mod
require (
github.com/labstack/echo/v4 v4.11.0
)
// main.go
import "github.com/labstack/echo/v4"
func main() {
e := echo.New()
e.GET("/", HomeHandler)
e.POST("/api/products", jwtMiddleware, CreateProduct)
e.Start(":8080")
}
Fiber (github.com/gofiber/fiber)
Framework ID: go_fiber
Fiber is an Express-inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go.
Capabilities:
- ✅ REST API endpoint discovery
- ✅ Route parameter detection
- ✅ Middleware and authentication detection
- ✅ Struct-based model discovery
- ✅ Service layer identification
- ✅ Actor extraction from roles
- ✅ System boundary mapping
- ✅ Use case generation
Example Detection:
// go.mod
require (
github.com/gofiber/fiber/v2 v2.50.0
)
// main.go
import "github.com/gofiber/fiber/v2"
func main() {
app := fiber.New()
app.Get("/", HomeHandler)
app.Post("/api/posts", authRequired, CreatePost)
app.Listen(":3000")
}
Detection Mechanism
RE-cue detects Go frameworks through a multi-factor scoring system:
Project Files (30% weight):
go.mod- Module definitiongo.sum- Dependency checksumsmain.go- Application entry point
Code Patterns (50% weight):
- Framework import statements in
go.mod - HTTP method calls (GET, POST, PUT, DELETE, PATCH)
- Framework-specific routing patterns
- Framework import statements in
Project Structure (20% weight):
- Presence of
main.go - Standard Go project layout
- Presence of
Exclusion Rules:
- Mutually exclusive framework detection (prevents false positives)
Analysis Features
Endpoint Discovery
The analyzer scans .go files for route definitions:
Gin Patterns:
r.GET("/path", handler)
router.POST("/path", middleware, handler)
engine.PUT("/path/:id", handler)
Echo Patterns:
e.GET("/path", handler)
echo.POST("/path", middleware, handler)
app.Add("GET", "/path", handler)
Fiber Patterns:
app.Get("/path", handler)
fiber.Post("/path", middleware, handler)
app.Add("GET", "/path", handler)
Authentication Detection
The analyzer identifies protected endpoints by detecting authentication middleware:
// Detected as authenticated
r.POST("/api/users", authMiddleware, CreateUser)
e.PUT("/admin/config", jwtMiddleware, UpdateConfig)
app.Delete("/posts/:id", tokenVerify, DeletePost)
// Detected as public
r.GET("/api/public/data", GetPublicData)
Recognized Auth Keywords:
auth,jwt,token,bearerprotected,requireauthverifytoken,checkauth
Model Discovery
The analyzer discovers Go structs as data models:
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"unique;not null"`
Email string `json:"email" gorm:"unique;not null"`
Password string `json:"-" gorm:"not null"`
Role string `json:"role" gorm:"default:user"`
}
Model Locations:
models/directorymodel/directoryentities/directorydomain/directory- Any
.gofile with struct definitions
Excluded Structs:
- Config, Handler, Controller, Service
- Middleware, Router, Request, Response
Service Discovery
Services are identified from:
services/directoryservice/directoryhandlers/directoryhandler/directory- Files with
*Service.gonaming pattern
Actor Discovery
Actors are extracted from:
- Role Definitions:
const (
RoleAdmin = "admin"
RoleUser = "user"
RoleModerator = "moderator"
)
- Default Actors:
- User (end_user)
- Admin (internal_user)
- Guest (end_user)
System Boundaries
Three main boundaries are identified:
REST API (external)
- All discovered endpoints
- Controllers and handlers
Database (data)
- All discovered models
- Data structures
Business Logic (internal)
- All discovered services
- Business rules
Use Case Extraction
Use cases are generated from endpoints:
UC01: View User
- Actor: User
- Precondition: None
- Main Scenario:
1. User sends GET request to /api/users
2. System processes the request
3. System returns response
- Postcondition: User is viewed
UC02: Create User
- Actor: Admin
- Precondition: Admin is authenticated
- Main Scenario:
1. User sends POST request to /api/users
2. System processes the request
3. System returns response
- Postcondition: User is created
Usage
Command Line
# Analyze a Gin project
reverse-engineer /path/to/gin-project
# Analyze with verbose output
reverse-engineer /path/to/echo-project --verbose
# Generate specific outputs
reverse-engineer /path/to/fiber-project --spec --api-spec --use-cases
Python API
from pathlib import Path
from reverse_engineer.frameworks import create_analyzer
# Auto-detect and create analyzer
project_path = Path("/path/to/go-project")
analyzer = create_analyzer(project_path, verbose=True)
# Discover components
endpoints = analyzer.discover_endpoints()
models = analyzer.discover_models()
services = analyzer.discover_services()
actors = analyzer.discover_actors()
boundaries = analyzer.discover_system_boundaries()
use_cases = analyzer.extract_use_cases()
# Access results
print(f"Found {len(endpoints)} endpoints")
for endpoint in endpoints:
print(f" {endpoint.method} {endpoint.path}")
Direct Framework Analyzer
from pathlib import Path
from reverse_engineer.frameworks.go import GinAnalyzer, EchoAnalyzer, FiberAnalyzer
# Use specific analyzer
gin_analyzer = GinAnalyzer(Path("/path/to/gin-project"), verbose=True)
endpoints = gin_analyzer.discover_endpoints()
echo_analyzer = EchoAnalyzer(Path("/path/to/echo-project"), verbose=True)
models = echo_analyzer.discover_models()
fiber_analyzer = FiberAnalyzer(Path("/path/to/fiber-project"), verbose=True)
services = fiber_analyzer.discover_services()
Configuration
Framework-Specific Patterns
You can extend the analyzers by subclassing:
from reverse_engineer.frameworks.go import GinAnalyzer
class CustomGinAnalyzer(GinAnalyzer):
def _check_authentication(self, lines, current_line):
# Custom authentication detection logic
return super()._check_authentication(lines, current_line)
Limitations
Current Limitations
Dynamic Routes:
- Dynamically generated routes may not be detected
- Routes defined at runtime are not analyzed
Complex Middleware:
- Middleware chains may require manual verification
- Custom middleware patterns might not be recognized
ORM Patterns:
- Only struct-based models are detected
- Dynamic model generation is not supported
Version Detection:
- Requires
go.modfile with explicit version numbers - Indirect dependencies may not be analyzed
- Requires
Workarounds
For Dynamic Routes:
- Document routes in comments
- Use static route definitions where possible
For Complex Middleware:
- Follow standard naming conventions
- Use recognized auth keywords in middleware names
For Custom Patterns:
- Extend analyzer classes
- Override detection methods
Best Practices
Project Structure
Follow standard Go project layout for best results:
project/
├── go.mod
├── go.sum
├── main.go
├── handlers/
│ ├── user_handler.go
│ └── product_handler.go
├── models/
│ ├── user.go
│ └── product.go
├── services/
│ ├── user_service.go
│ └── product_service.go
└── middleware/
└── auth.go
Naming Conventions
- Use descriptive handler names:
UserHandler,ProductHandler - Name services consistently:
UserService,AuthService - Keep model names clear:
User,Product,Order - Use standard middleware names:
authMiddleware,jwtMiddleware
Code Organization
- Group related routes together
- Keep models in dedicated files
- Separate business logic into services
- Use consistent authentication patterns
Examples
See the tests/test_go_analyzers.py file for comprehensive examples of:
- Route discovery
- Model analysis
- Service identification
- Actor extraction
- Complete workflow integration
Troubleshooting
Low Confidence Detection
Problem: Framework detected with low confidence (<50%)
Solutions:
- Ensure
go.modexists and includes framework dependency - Add
go.sumfile with dependency checksums - Include
main.gowith framework import - Use framework-specific route patterns
Missing Endpoints
Problem: Some endpoints not discovered
Solutions:
- Check route definition syntax matches supported patterns
- Ensure routes are in
.gofiles (not test files) - Verify file is not in excluded directories
- Check for typos in method names (GET, POST, etc.)
Incorrect Authentication Detection
Problem: Public routes marked as authenticated or vice versa
Solutions:
- Place middleware between route path and handler
- Use recognized auth keywords in middleware names
- Follow framework conventions for middleware placement
- Verify comma-separated middleware syntax
Contributing
To add support for additional Go frameworks or improve existing analyzers:
- Create a new analyzer in
reverse_engineer/frameworks/go/ - Extend
BaseAnalyzerclass - Implement all required methods
- Add detection rules to
detector.py - Update
factory.pyto include new framework - Add comprehensive tests
- Update this documentation
See the existing analyzers for reference implementations.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.