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

extract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package extract provides a reusable source-signature extraction API backed by the language-specific packages in this module. Parse returns source snippets, a function count, and optionally processed full content in a stable result shape suitable for source-packaging tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanSource

func CleanSource(src []byte, opts Options, out *bytes.Buffer)

CleanSource applies comment stripping, indent trimming, and blank line collapsing in a single pass without intermediate string allocations.

func ProcessContent

func ProcessContent(s string, opts Options) string

ProcessContent applies the requested comment, indentation, and blank-line cleanup.

func StripComments

func StripComments(content string) string

StripComments removes line and block comments while preserving string literals.

func TrimBlankLines

func TrimBlankLines(s string) string

TrimBlankLines collapses runs of blank lines.

func TrimIndent

func TrimIndent(s string) string

TrimIndent removes leading indentation from every line.

func Truncate

func Truncate(src []byte, opts Options, snippets []string) string

Truncate keeps configured head and tail lines and marks omitted middle content.

Types

type Options

type Options struct {
	ExportedOnly   bool
	StripComments  bool
	TrimIndent     bool
	TrimBlankLines bool
	MaxLines       int
	MaxLinesHead   int
	MaxLinesTail   int
	RemoveBodyFunc bool
}

Options controls signature filtering and content cleanup for Parse.

type Result

type Result struct {
	Snippets  []string
	FuncCount int
	Content   string
}

Result contains extracted declaration snippets, the function count, or processed full content when no signature snippets are available.

func Parse

func Parse(path string, src []byte, lang string, opts Options) (Result, error)

Parse dispatches source to the language-specific extractor selected by lang. The result shape is stable for callers that package or summarize source files.

Jump to

Keyboard shortcuts

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