analyzer

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 12 Imported by: 0

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

type BusInfo struct {
	BusMethods map[*ssa.Function]bool
	Dispatches []Dispatch
}

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

type Dispatch struct {
	Caller   *ssa.Function
	Message  string
	Handlers []*ssa.Function
}

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.

func (*Func) Display

func (f *Func) Display() string

Display returns a human label like "(*UserController).GetUser" or "GetUser".

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 Load

func Load(dir string) (*Result, error)

Load analyzes the Go module rooted at dir ("." for cwd).

func (*Result) Buses

func (r *Result) Buses() *BusInfo

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

func (r *Result) FuncFor(obj *types.Func) *Func

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

func (r *Result) InProject(pkgPath string) bool

InProject reports whether an import path belongs to the analyzed project.

func (*Result) Ports

func (r *Result) Ports() []*Port

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

func (r *Result) WSUpgraders() map[*ssa.Function]bool

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".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL