Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package ui serves the graphmaster graph explorer (`graphmaster ui`): a small JSON API over graph.db plus a static, build-free frontend (plain JavaScript and a vendored cytoscape).

The graph is never loaded whole. Every endpoint answers one bounded question — a search, one symbol, an ego graph, a file, one directory level or an impact set — and no response carries more than MaxElements cytoscape elements.

The server binds to 127.0.0.1 only. Every request must carry the random per-process token in its URL (?token=...) and a Host header naming localhost or 127.0.0.1, which blocks other local users without the URL and DNS-rebinding pages alike. API requests freshen the index first with a short lock budget, like the query tools.

Index

Constants

View Source
const (

	// DefaultFreshenBudget is the lock wait before an API request answers
	// from the current graph; the UI favours latency over completeness.
	DefaultFreshenBudget = 2 * time.Second
)

Response and request bounds.

Variables

This section is empty.

Functions

func Listen

func Listen(port int) (net.Listener, error)

Listen binds the loopback interface; port 0 picks a free port.

Types

type EgoResponse

type EgoResponse struct {
	GraphResponse
	Center string `json:"center"`
}

EgoResponse answers /api/ego.

type ElemData

type ElemData struct {
	ID     string `json:"id"`
	Parent string `json:"parent,omitempty"`
	Source string `json:"source,omitempty"`
	Target string `json:"target,omitempty"`
	Label  string `json:"label,omitempty"`
	// Kind is the node kind, the edge kind, or "file"/"dir" for groups.
	Kind string `json:"kind,omitempty"`
	// Ref is the nodes.id of a symbol or the files.id of a file.
	Ref   int64  `json:"ref,omitempty"`
	QName string `json:"qname,omitempty"`
	Path  string `json:"path,omitempty"`
	Lang  string `json:"lang,omitempty"`
	Start int    `json:"start,omitempty"`
	End   int    `json:"end,omitempty"`
	// Conf is an edge's best confidence; Count the edges it aggregates.
	Conf  int `json:"conf,omitempty"`
	Count int `json:"count,omitempty"`
	// Depth is the distance from the ego center or impact seeds.
	Depth int `json:"depth,omitempty"`
	// Aggregates of file and directory nodes.
	Files   int `json:"files,omitempty"`
	Symbols int `json:"symbols,omitempty"`
	LOC     int `json:"loc,omitempty"`
}

ElemData is an element's data object. Element ids are "n<node id>" for symbols, "f<file id>" for files and "g:<path>" for directory groups.

type Element

type Element struct {
	Group   string   `json:"group"`
	Data    ElemData `json:"data"`
	Classes string   `json:"classes,omitempty"`
}

Element is one cytoscape element (group "nodes" or "edges").

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is the body of every non-200 API answer.

type FileInfo

type FileInfo struct {
	ID      int64  `json:"id"`
	Path    string `json:"path"`
	Lang    string `json:"lang"`
	LOC     int    `json:"loc"`
	Status  string `json:"status"`
	Symbols int    `json:"symbols"`
}

FileInfo summarizes a files row.

type FileResponse

type FileResponse struct {
	GraphResponse
	File FileInfo `json:"file"`
}

FileResponse answers /api/file.

type GraphResponse

type GraphResponse struct {
	Banner   string    `json:"banner"`
	Elements []Element `json:"elements"`
	// Truncated reports that elements were dropped to honour a cap.
	Truncated bool `json:"truncated"`
}

GraphResponse is the common part of every graph endpoint.

type ImpactResponse

type ImpactResponse struct {
	GraphResponse
	// Seeds are the element ids of the starting definitions.
	Seeds []string `json:"seeds"`
	// Affected, Files and Tests count the whole reverse closure, even
	// when the elements are truncated.
	Affected int  `json:"affected"`
	Files    int  `json:"files"`
	Tests    int  `json:"tests"`
	Depth    int  `json:"depth"`
	MinConf  int  `json:"minConf"`
	Capped   bool `json:"walkCapped,omitempty"`
}

ImpactResponse answers /api/impact.

type NodeResponse

type NodeResponse struct {
	Banner   string   `json:"banner"`
	Symbol   Symbol   `json:"symbol"`
	Parent   *Symbol  `json:"parent,omitempty"`
	Children []Symbol `json:"children"`
	// MoreChildren counts children beyond the listed ones.
	MoreChildren int `json:"moreChildren,omitempty"`
	// In and Out count resolved edges by kind (incoming, outgoing).
	In  map[string]int `json:"in"`
	Out map[string]int `json:"out"`
	// Unresolved counts outgoing references with no indexed target.
	Unresolved int      `json:"unresolved"`
	Source     *Snippet `json:"source,omitempty"`
}

NodeResponse answers /api/node: details for the side panel.

type Options

type Options struct {
	// Freshener runs before every API request. Nil uses the backend when
	// it implements query.Freshener.
	Freshener query.Freshener
	// FreshenBudget bounds the wait for the write lock (default 2s).
	FreshenBudget time.Duration
	// Token is the URL secret; empty generates a random one.
	Token string
	// MaxElements overrides the per-response element cap (tests only;
	// default and maximum 1500).
	MaxElements int
}

Options configure a Server.

type PackagesResponse

type PackagesResponse struct {
	GraphResponse
	Prefix string `json:"prefix"`
	// Parent is the prefix one level up ("" at the root).
	Parent string `json:"parent"`
}

PackagesResponse answers /api/packages: one directory level.

type SearchResponse

type SearchResponse struct {
	Banner  string     `json:"banner"`
	Query   string     `json:"query"`
	Symbols []Symbol   `json:"symbols"`
	Files   []FileInfo `json:"files"`
	More    bool       `json:"more"`
}

SearchResponse answers /api/search.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the UI's HTTP handler. It is safe for concurrent use.

func New

func New(b query.Backend, opts Options) *Server

New returns a Server over the index b (normally an *index.Indexer).

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the guarded handler (token, Host and method checks).

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve answers requests on ln until ctx is cancelled, then shuts down gracefully. It returns nil after a cancellation.

func (*Server) Token

func (s *Server) Token() string

Token returns the secret every request must carry.

func (*Server) URL

func (s *Server) URL(addr net.Addr) string

URL is the address to open in a browser for a listener at addr.

type Snippet

type Snippet struct {
	Start     int      `json:"start"`
	Lines     []string `json:"lines"`
	Truncated bool     `json:"truncated,omitempty"`
	Error     string   `json:"error,omitempty"`
}

Snippet is the source of a symbol, starting at line Start.

type Symbol

type Symbol struct {
	ID       int64  `json:"id"`
	FileID   int64  `json:"fileId"`
	ParentID int64  `json:"parentId,omitempty"`
	Kind     string `json:"kind"`
	Name     string `json:"name"`
	QName    string `json:"qname"`
	Path     string `json:"path"`
	Lang     string `json:"lang"`
	Start    int    `json:"start"`
	End      int    `json:"end"`
	Sig      string `json:"sig,omitempty"`
	Exported bool   `json:"exported,omitempty"`
	Test     bool   `json:"test,omitempty"`
	Decl     bool   `json:"declaration,omitempty"`
	SKey     string `json:"skey"`
}

Symbol is a definition as the API reports it.

Jump to

Keyboard shortcuts

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