Documentation
¶
Index ¶
- type FileImpactResult
- type GoDepFind
- func (g *GoDepFind) AnalyzeFileImpact(mainInputFileRelativePath, fileName, filePath, event string) (*FileImpactResult, error)
- func (g *GoDepFind) CheckFileOwnership(mainInputFileRelativePath, fileName, filePath string) (string, error)
- func (g *GoDepFind) DebugThisFileIsMine(mainInputFileRelativePath, fileAbsPath, event string) (bool, error)
- func (g *GoDepFind) FindReverseDeps(sourcePath string, targetPaths []string) ([]string, error)
- func (g *GoDepFind) FindReverseDepsForFile(mainInputFileRelativePath, fileName, filePath string) ([]string, error)
- func (g *GoDepFind) GoFileComesFromMain(fileName string) ([]string, error)
- func (g *GoDepFind) SetTestImports(enabled bool)
- func (g *GoDepFind) ThisFileIsMine(mainInputFileRelativePath, fileAbsPath, event string) (bool, error)
- func (g *GoDepFind) ValidateInputForProcessing(mainInputFileRelativePath, fileName, filePath string) (bool, error)
- type GoFileValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileImpactResult ¶
type FileImpactResult struct {
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
BelongsToHandler bool `json:"belongs_to_handler"`
AffectedMains []string `json:"affected_mains"`
Impact string `json:"impact"`
}
FileImpactResult represents the result of file impact analysis
type GoDepFind ¶
type GoDepFind struct {
// contains filtered or unexported fields
}
func (*GoDepFind) AnalyzeFileImpact ¶
func (g *GoDepFind) AnalyzeFileImpact(mainInputFileRelativePath, fileName, filePath, event string) (*FileImpactResult, error)
AnalyzeFileImpact analyzes the impact of a file change with validation Yet another example showing reusability
func (*GoDepFind) CheckFileOwnership ¶
func (g *GoDepFind) CheckFileOwnership(mainInputFileRelativePath, fileName, filePath string) (string, error)
CheckFileOwnership checks if a file belongs to a handler with validation Another example of reusing the validation function
func (*GoDepFind) DebugThisFileIsMine ¶
func (g *GoDepFind) DebugThisFileIsMine(mainInputFileRelativePath, fileAbsPath, event string) (bool, error)
DebugThisFileIsMine provides detailed debugging for production issues with ThisFileIsMine returning unexpected results
func (*GoDepFind) FindReverseDeps ¶
FindReverseDeps finds packages in sourcePath that import any of the targetPaths
func (*GoDepFind) FindReverseDepsForFile ¶
func (g *GoDepFind) FindReverseDepsForFile(mainInputFileRelativePath, fileName, filePath string) ([]string, error)
FindReverseDepsForFile finds reverse dependencies for a specific file with validation This is an example of how to reuse the validation function in other public APIs
func (*GoDepFind) GoFileComesFromMain ¶
GoFileComesFromMain finds which main packages depend on the given file (cached version) fileName: the name of the file to check (e.g., "module3.go") Returns: slice of main package paths that depend on this file
func (*GoDepFind) SetTestImports ¶
SetTestImports enables or disables inclusion of test imports
func (*GoDepFind) ThisFileIsMine ¶
func (g *GoDepFind) ThisFileIsMine(mainInputFileRelativePath, fileAbsPath, event string) (bool, error)
ThisFileIsMine decides whether the provided handler (identified by its main file path relative to the module root) should handle an event for the given file. It normalizes paths, validates the handler main file exists, updates internal caches when a main file is written (so dynamic import changes are recognized), and finally uses package dependency analysis to decide file ownership.
Important: preference is given to checking the specific handler main-file imports (not just directory-level mains). That lets the finder disambiguate multiple `main` packages that may live in the same directory but are selected via build tags (for example: two mains in one folder with `//go:build wasm` vs `//go:build !wasm`). In those cases the exact main file (and its build tags/imports) determines ownership.
Inputs:
- mainInputFileRelativePath: handler main file (e.g. "pwa/main.server.go")
- fileAbsPath: target file path (absolute or relative to module root)
- event: one of "write","create","remove","rename" (drives cache ops)
Returns: (bool, error) — true when the handler should process the file.
func (*GoDepFind) ValidateInputForProcessing ¶
func (g *GoDepFind) ValidateInputForProcessing(mainInputFileRelativePath, fileName, filePath string) (bool, error)
ValidateInputForProcessing validates handler and file before processing This function provides centralized validation that can be reused across multiple API endpoints.
It performs the following validations: 1. Handler validation (nil check and main file path validation) 2. Go file validation (syntax, completeness, and write-in-progress detection)
Returns:
- shouldProcess: true if processing should continue, false if file should be skipped
- error: validation error that should be returned to caller, or nil if validation passed
Usage patterns:
- shouldProcess=true, error=nil: Continue with normal processing
- shouldProcess=false, error=nil: Skip processing (file is being written, empty, etc.)
- shouldProcess=false, error!=nil: Return error to caller (invalid handler, etc.)
ValidateInputForProcessing validates handler and file before processing This function provides centralized validation that can be reused across multiple API endpoints.
It performs the following validations: 1. Handler validation (non-empty main file path) 2. Go file validation (syntax, completeness, and write-in-progress detection)
Returns:
- shouldProcess: true if processing should continue, false if file should be skipped
- error: validation error that should be returned to caller, or nil if validation passed
Usage patterns:
- shouldProcess=true, error=nil: Continue with normal processing
- shouldProcess=false, error=nil: Skip processing (file is being written, empty, etc.)
- shouldProcess=false, error!=nil: Return error to caller (invalid handler, etc.)
type GoFileValidator ¶
type GoFileValidator struct{}
GoFileValidator provides methods to validate Go files before processing
func NewGoFileValidator ¶
func NewGoFileValidator() *GoFileValidator
NewGoFileValidator creates a new validator instance
func (*GoFileValidator) HasMinimumGoContent ¶
func (v *GoFileValidator) HasMinimumGoContent(filePath string) (bool, error)
HasMinimumGoContent checks if file has at least a package declaration
func (*GoFileValidator) IsFileBeingWritten ¶
func (v *GoFileValidator) IsFileBeingWritten(filePath string) (bool, error)
IsFileBeingWritten tries to detect if a file is currently being written by checking for incomplete content patterns
func (*GoFileValidator) IsValidGoFile ¶
func (v *GoFileValidator) IsValidGoFile(filePath string) (bool, error)
IsValidGoFile checks if a Go file is valid and safe to process