gocode

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gocode is the Go backend for `sf code`: a structural summary of a Go source file (package, imports, types, func/method signatures, consts, vars) and single-symbol slicing — via the stdlib go/parser (syntax only, no type-checking), so it works on any file regardless of whether it compiles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Slice

func Slice(src []byte, symbol string) (string, []string, error)

Slice returns the source of one named symbol (signature + body + doc) from src, or the available names when not found.

func Summarize

func Summarize(w io.Writer, path, format string, exported, _, brief bool) (map[string]any, error)

Summarize writes the structural summary of the Go file at path to w in the given format (toon|md|json) and returns a call-log summary map. api (PHP's effective-surface flag) is not meaningful for Go and is ignored. brief requests the signature-only cut — see Brief for exactly what it drops.

Types

type GoFile

type GoFile struct {
	File    string    `json:"file"`
	Package string    `json:"package"`
	Imports []string  `json:"imports"`
	Types   []GoType  `json:"types"`
	Funcs   []GoFunc  `json:"funcs"` // free funcs and methods (Recv set)
	Consts  []GoValue `json:"consts,omitempty"`
	Vars    []GoValue `json:"vars,omitempty"`
}

GoFile is the structural summary of one Go source file.

func ReadGo

func ReadGo(path string) (*GoFile, error)

ReadGo parses a single Go file (syntax only — no type-checking, no build), so it works on any file regardless of whether its package compiles.

func (*GoFile) Brief added in v0.6.0

func (g *GoFile) Brief()

Brief collapses field/value-level detail for a signature-only view: struct field lists (and their tags) disappear — kind and name stay — while interface Detail is left alone (it's already just method signatures, the same level of detail as a free func's Sig). Consts and vars drop their type column, leaving bare names — the const/var equivalent of a struct's fields, and no more useful in a whole-package map. Composes with FilterExported in either order.

func (*GoFile) FilterExported

func (g *GoFile) FilterExported()

FilterExported drops unexported (lowercase) symbols, leaving the API view.

type GoFunc

type GoFunc struct {
	Recv     string `json:"recv,omitempty"` // "" for free funcs, else "*Server" / "Server"
	Name     string `json:"name"`
	Sig      string `json:"sig"` // "(params) results"
	Exported bool   `json:"exported"`
}

type GoType

type GoType struct {
	Kind     string `json:"kind"` // struct | interface | alias | defined
	Name     string `json:"name"`
	Detail   string `json:"detail,omitempty"` // struct fields | interface methods | underlying type — blank in Brief mode for structs
	Exported bool   `json:"exported"`
}

type GoValue

type GoValue struct {
	Name     string `json:"name"`
	Type     string `json:"type,omitempty"`
	Exported bool   `json:"exported"`
}

Jump to

Keyboard shortcuts

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