scanner

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanHandlerPayloadInfo

func ScanHandlerPayloadInfo(pkgPath string) (map[string]PayloadInfo, error)

ScanHandlerPayloadInfo analyzes handler functions to infer payload semantics (kind, required, parser hints). It complements JSON payload detection; if both numeric and JSON patterns appear JSON wins.

func ScanHandlerReturnDTOs

func ScanHandlerReturnDTOs(pkgPath string) (map[string]string, error)

ScanHandlerReturnDTOs scans handler implementations to find the apitypes.* struct passed to json.Marshal, and returns a mapping of handler factory name (e.g., "BusList") to DTO type name (e.g., "BusListResponse"). If no DTO is found, the handler is omitted.

Types

type ConstantInfo

type ConstantInfo struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"` // Can be int, string, etc.
	Type  string      `json:"type"`  // e.g., "int", "uint8", "string"
}

ConstantInfo represents a single constant definition

type DTOSchema

type DTOSchema struct {
	Name   string      `json:"name"`   // Type name (e.g., "BusCreateResponse")
	Fields []FieldInfo `json:"fields"` // Struct fields
}

DTOSchema represents the schema of a response DTO.

func ScanDTOs

func ScanDTOs(filePath string) ([]DTOSchema, error)

ScanDTOs scans a Go file containing DTO struct definitions and extracts their schemas.

func ScanDTOsInPackage

func ScanDTOsInPackage(pkgPath string) ([]DTOSchema, error)

ScanDTOsInPackage scans all Go files in a package and extracts DTO schemas.

type DeviceConstants

type DeviceConstants struct {
	DeviceType string         `json:"deviceType"`
	Constants  []ConstantInfo `json:"constants"`
	Maps       []MapInfo      `json:"maps"`
}

DeviceConstants holds all constants and maps for a device package

func ScanDeviceConstants

func ScanDeviceConstants(devicePkgPath string) (*DeviceConstants, error)

ScanDeviceConstants scans a device package directory for constants and maps

type FieldInfo

type FieldInfo struct {
	Name     string `json:"name"`     // Go field name (e.g., "BusID")
	JSONName string `json:"jsonName"` // JSON tag name (e.g., "busId")
	Type     string `json:"type"`     // Go type (e.g., "uint32", "[]Device")
	TypeKind string `json:"typeKind"` // Kind: "primitive", "slice", "struct"
	Optional bool   `json:"optional"` // Whether field can be omitted (pointer or has omitempty)
}

FieldInfo describes a single field in a DTO.

type MapInfo

type MapInfo struct {
	Name      string                 `json:"name"`
	KeyType   string                 `json:"keyType"`
	ValueType string                 `json:"valueType"`
	Entries   map[string]interface{} `json:"entries"` // Key as string, value as interface{}
}

MapInfo represents a map variable with its entries

type PayloadInfo

type PayloadInfo struct {
	Kind       PayloadKind `json:"kind"`                 // none|numeric|json|string
	Required   bool        `json:"required"`             // true if handler rejects empty payload
	ParserHint string      `json:"parserHint,omitempty"` // e.g., uint32, DeviceCreateRequest, deviceID
	RawType    string      `json:"rawType,omitempty"`    // Underlying Go type name for JSON / numeric width
	Notes      string      `json:"notes,omitempty"`      // Additional guidance for generators
}

PayloadInfo describes how a route's req.Payload is interpreted.

type PayloadKind

type PayloadKind string

PayloadKind enumerates recognized payload semantics.

const (
	PayloadNone    PayloadKind = "none"
	PayloadNumeric PayloadKind = "numeric"
	PayloadJSON    PayloadKind = "json"
	PayloadString  PayloadKind = "string"
)

type RouteInfo

type RouteInfo struct {
	Path        string            `json:"path"`        // e.g., "bus/{id}/list"
	Method      string            `json:"method"`      // "Register" or "RegisterStream"
	Handler     string            `json:"handler"`     // e.g., "BusList"
	PathParams  map[string]string `json:"pathParams"`  // e.g., {"id": "string"}
	ResponseDTO string            `json:"responseDTO"` // Name of DTO type returned (e.g., "BusListResponse"), empty if none
	Payload     PayloadInfo       `json:"payload"`     // payload classification
}

RouteInfo describes a discovered API route.

func EnrichRoutesWithHandlerInfo

func EnrichRoutesWithHandlerInfo(routes []RouteInfo, handlerPkgPath string) ([]RouteInfo, error)

EnrichRoutesWithHandlerInfo scans handler implementations and enriches routes with argument metadata.

func ScanRoutes

func ScanRoutes(filePath string) ([]RouteInfo, error)

ScanRoutes scans the specified Go file for router.Register() and router.RegisterStream() calls and returns metadata about discovered routes.

func ScanRoutesInPackage

func ScanRoutesInPackage(pkgPath string) ([]RouteInfo, error)

ScanRoutesInPackage scans all Go files in the specified directory (non-recursively) and aggregates route information.

type WireField

type WireField struct {
	Name string `json:"name"` // Field name (e.g., "modifiers", "keys")
	Type string `json:"type"` // Wire type token (e.g., "u8", "i16", may include array marker like "u8*count")
	Spec string `json:"spec"` // Full spec from tag (e.g., "keys:u8*count")
}

WireField represents a single field in a wire protocol struct

type WireTag

type WireTag struct {
	Device    string      `json:"device"`    // "keyboard", "mouse", "xbox360"
	Direction string      `json:"direction"` // "c2s" or "s2c"
	Fields    []WireField `json:"fields"`
}

WireTag represents a parsed viiper:wire comment

type WireTags

type WireTags struct {
	Tags map[string]map[string]*WireTag // device -> direction -> tag
}

WireTags holds all wire tags for all devices

func ScanWireTags

func ScanWireTags(devicePkgPaths []string) (*WireTags, error)

ScanWireTags scans all device packages for viiper:wire comments

func (*WireTags) GetTag

func (wt *WireTags) GetTag(device, direction string) *WireTag

GetTag retrieves the wire tag for a device and direction

func (*WireTags) HasDirection

func (wt *WireTags) HasDirection(device, direction string) bool

HasDirection checks if a device has a wire tag for the given direction

Jump to

Keyboard shortcuts

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