parser

package
v0.1.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ReasonDynamicPattern      = "dynamic_pattern"
	ReasonOpaqueMiddleware    = "opaque_middleware"
	ReasonCrossPackageModel   = "cross_package_model"
	ReasonComplexTypeArg      = "complex_type_arg"
	ReasonCrossPackageHandler = "cross_package_handler"
	ReasonOther               = "other"
)

Reason codes for diagnostics.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RouteRegistrations []RouteSymbol
	GenericFunctions   []FunctionSymbol
	ErrorFunctions     []FunctionSymbol
}

Config customizes symbols explored by the parser. Every slice is authoritative.

func DefaultConfig

func DefaultConfig() Config

type Diagnostic

type Diagnostic struct {
	File         string `json:"file"`
	Line         int    `json:"line"`
	Column       int    `json:"column"`
	Reason       string `json:"reason"` // dynamic_pattern|opaque_middleware|cross_package_model|complex_type_arg|other
	Message      string `json:"message"`
	OmitsOpenAPI bool   `json:"omits_openapi"`
}

Diagnostic is a host-side analysis finding for an incomplete route-like site.

func CheckPackage

func CheckPackage(dir string) ([]Diagnostic, error)

CheckPackage runs analysis and returns diagnostics for undiscoverable route candidates. Non-empty diagnostics mean OpenAPI would omit incomplete candidates.

func CheckPackageWithConfig

func CheckPackageWithConfig(dir string, config Config) ([]Diagnostic, error)

CheckPackageWithConfig runs diagnostics with an authoritative symbol config.

func (Diagnostic) String

func (d Diagnostic) String() string

String formats a diagnostic for CLI output.

type FunctionSymbol

type FunctionSymbol struct{ PackagePath, Name string }

type Handler

type Handler struct {
	Form string `json:"form"`           // named | inline | struct
	Name string `json:"name,omitempty"` // function or type name when known
}

Handler describes how the leaf handler was expressed in source.

type Result

type Result struct {
	Routes      []Route      `json:"routes"`
	Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}

Result is the structured parse output for a single Go package.

func ParsePackage

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

ParsePackage analyzes Go sources in dir (same package only) and returns statically discoverable httpbind route IR.

Symbol identity for route registration and httpbind calls is resolved with go/types (host-side only); see rule:go-types-symbol-identity.

func ParsePackageFiles

func ParsePackageFiles(files []string) (*Result, error)

ParsePackageFiles is like ParsePackage but accepts an explicit file list (used by tests when embedding small snippets). Each path must exist.

func ParsePackageWithConfig

func ParsePackageWithConfig(dir string, config Config) (*Result, error)

ParsePackageWithConfig analyzes dir with customizable discovery symbols.

func (Result) JSON

func (r Result) JSON() ([]byte, error)

JSON returns canonical indented JSON for golden files.

func (*Result) Normalize

func (r *Result) Normalize()

Normalize sorts routes and nested slices for stable golden comparisons.

type Route

type Route struct {
	Method          string      `json:"method"`
	Path            string      `json:"path"`
	Handler         Handler     `json:"handler"`
	Request         string      `json:"request,omitempty"`
	Response        string      `json:"response,omitempty"`
	Stream          string      `json:"stream,omitempty"` // element type when response is Stream[T]
	Errors          []string    `json:"errors,omitempty"`
	SuccessStatuses []int       `json:"success_statuses,omitempty"` // 200 from Write, others from WriteStatus
	Wrappers        WrapperMeta `json:"wrappers"`
}

Route is one statically discovered net/http route registration.

type RouteSymbol

type RouteSymbol struct {
	PackagePath, Name                 string
	ReceiverPackagePath, ReceiverType string
}

type WrapperMeta

type WrapperMeta struct {
	AllowQuerySemicolons bool   `json:"allow_query_semicolons"`
	MaxRequestBodyBytes  *int64 `json:"max_request_body_bytes,omitempty"`
	StrippedPrefix       string `json:"stripped_prefix,omitempty"`
	Timeout              string `json:"timeout,omitempty"`
	TimeoutMessage       string `json:"timeout_message,omitempty"`
}

WrapperMeta holds statically known stdlib wrapper metadata.

Jump to

Keyboard shortcuts

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