Documentation
¶
Overview ¶
Package analyzer loads a Go module from source, builds its SSA form and a CHA (Class Hierarchy Analysis) call graph, and exposes the project's own functions with their source positions. CHA resolves interface dispatch to all implementing types, which is accurate for the common single-implementation layered case (controller -> service -> repository through interfaces).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BusInfo ¶
BusInfo is the result of bus detection: the bus methods (used as call-graph barriers so CHA's over-approximation through the bus is dropped) and the precise dispatch edges recovered from registration sites.
type Dispatch ¶
Dispatch is a resolved mediator dispatch: a caller sends a message through a bus and the message routes to one or more concrete handlers.
type Func ¶
type Func struct {
SSA *ssa.Function
Pkg string // import path
Recv string // receiver type without package qualifier, e.g. "*UserController" ("" for free functions)
Name string // method/function name, e.g. "GetUser"
File string // absolute source file
Line int
Col int
}
Func is a project function/method discovered during analysis.
type Port ¶
type Port struct {
Name string
Pkg string
File string
Line int
Col int
Methods []string
Callers map[*ssa.Function]bool // project funcs that invoke a method on this interface
ImplMethods map[*ssa.Function]bool // project methods that satisfy this interface
}
Port is a project-owned interface that is implemented by a project concrete type — i.e. a hexagonal "port". It records who uses it (callers that invoke its methods through the interface) and who implements it (the adapter methods that satisfy it). The builder decides whether a port is inbound or outbound from the layer of its implementers.
type Result ¶
type Result struct {
Module string // main module path (may be "")
Fset *token.FileSet
Prog *ssa.Program
Pkgs []*packages.Package
CallGraph *callgraph.Graph
// Funcs holds only project-owned functions, keyed by their SSA function.
Funcs map[*ssa.Function]*Func
// contains filtered or unexported fields
}
Result is the analyzed program.
func (*Result) Buses ¶
Buses detects command/query/event mediators. It learns bus types and their message->handler routing from registration calls (e.g. bus.Register(Cmd{}.Name(), NewCmdHandler(...))), then resolves dispatch sites (calls on a bus type passing a routed message) to the concrete handlers.
This recovers the routing a static call graph cannot: the bus stores handlers in a map keyed at runtime, so CHA would otherwise fan every dispatch out to every handler that implements the handler interface.
func (*Result) FuncFor ¶
FuncFor resolves a types.Func (e.g. a route handler) to its project Func, or nil if it isn't a known project function.
func (*Result) InProject ¶
InProject reports whether an import path belongs to the analyzed project.
func (*Result) Ports ¶
Ports finds every project interface implemented by a project concrete type, resolving its callers (interface-dispatch sites) and implementer methods.
func (*Result) WSUpgraders ¶ added in v0.6.0
WSUpgraders returns the project functions that perform a WebSocket upgrade — i.e. they call a websocket package's Upgrade (gorilla/websocket) or Accept (coder/nhooyr websocket). These are the handlers behind a WebSocket endpoint, so the builder can label their route "WS".