Documentation
¶
Index ¶
- Constants
- func CalculateRelativePath(fileName, currentPath, basePath string) string
- func GenerateComponentID(rootID, name, relativePath string) string
- func GenerateRootID() string
- func LanguageTypeToString(t enry.Type) string
- func NewMetadata(source string) map[string]interface{}
- type CategoriesConfig
- type CategoryDefinition
- type CategoryInfo
- type CompiledDependency
- type ComponentRef
- type ContentRule
- type Dependency
- type Edge
- type File
- type FileReader
- type License
- type Payload
- func (p *Payload) AddChild(service *Payload) *Payload
- func (p *Payload) AddDependency(dep Dependency)
- func (p *Payload) AddDockerReason(reason string)
- func (p *Payload) AddEdges(target *Payload)
- func (p *Payload) AddLanguage(language string)
- func (p *Payload) AddLanguageWithCount(language string, count int)
- func (p *Payload) AddLicense(license License)
- func (p *Payload) AddLicenseReason(reason string)
- func (p *Payload) AddPath(path string)
- func (p *Payload) AddPrimaryTech(tech string)
- func (p *Payload) AddReason(reason string)
- func (p *Payload) AddTech(tech string, reason string)
- func (p *Payload) AddTechs(techs map[string][]string)
- func (p *Payload) AssignIDs(rootID string)
- func (p *Payload) Combine(other *Payload)
- func (p *Payload) DetectLanguage(filename string, content []byte)
- func (p *Payload) GetFullPath() string
- func (p *Payload) HasPrimaryTech(tech string) bool
- func (p *Payload) SetComponentProperties(techKey string, properties map[string]interface{})
- func (p *Payload) SetComponentProperty(techKey, propertyKey string, value interface{})
- func (p *Payload) SetComponentType(componentType string)
- func (p *Payload) String() string
- type PrimaryLanguage
- type Provider
- type Rule
- type TechInfo
Constants ¶
const ( ScopeProd = "prod" ScopeDev = "dev" ScopeTest = "test" ScopeBuild = "build" ScopeOptional = "optional" ScopePeer = "peer" // Maven-specific scopes ScopeSystem = "system" ScopeImport = "import" )
Dependency scope constants
Variables ¶
This section is empty.
Functions ¶
func CalculateRelativePath ¶
CalculateRelativePath calculates the relative file path from basePath, normalizing it to start with "/" or return "/" for root. This eliminates the repeated pattern across all detectors.
func GenerateComponentID ¶
GenerateComponentID generates a deterministic 20-character ID for child components. It combines the root ID, component name, and relative path to create unique, reproducible IDs within a scan context. Components with different names at the same path will have different IDs.
func GenerateRootID ¶
func GenerateRootID() string
GenerateRootID generates a unique 12-character random ID for root/main components. Each scan gets a unique root ID, ensuring all component IDs within that scan are unique.
func LanguageTypeToString ¶
LanguageTypeToString converts enry.Type to string (programming, data, markup, prose)
func NewMetadata ¶
NewMetadata creates a new metadata map with the source field set This helper eliminates code duplication across parsers
Types ¶
type CategoriesConfig ¶
type CategoriesConfig struct {
Categories map[string]CategoryDefinition `yaml:"categories" json:"categories"`
}
CategoriesConfig represents the categories.yaml configuration file
type CategoryDefinition ¶
type CategoryDefinition struct {
IsComponent bool `yaml:"is_component" json:"is_component"`
CreateEdges *bool `yaml:"create_edges,omitempty" json:"create_edges,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
}
CategoryDefinition represents a technology category configuration
type CategoryInfo ¶
type CategoryInfo struct {
Name string `json:"name"`
IsComponent bool `json:"is_component"`
Description string `json:"description"`
}
CategoryInfo represents a single category entry
type CompiledDependency ¶
CompiledDependency is a pre-compiled dependency for performance
func (*CompiledDependency) Match ¶
func (cd *CompiledDependency) Match(s string) bool
Match checks if the dependency matches the given string
type ComponentRef ¶
type ComponentRef struct {
TargetID string `json:"target_id"` // Component ID being depended on
PackageName string `json:"package_name"` // Package name that created the link
}
ComponentRef represents a reference to another component in the same project
type ContentRule ¶
type ContentRule struct {
Type string `yaml:"type,omitempty" json:"type,omitempty"` // Match type: "regex" (default), "json-path", "json-schema", "yaml-path"
Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` // Regex pattern (for type=regex) or expected value (for path types)
Path string `yaml:"path,omitempty" json:"path,omitempty"` // JSON/YAML path (e.g., "$.$schema", "$.name")
Value string `yaml:"value,omitempty" json:"value,omitempty"` // Expected value for path matching (exact match or regex if starts/ends with /)
Extensions []string `yaml:"extensions,omitempty" json:"extensions,omitempty"` // Optional: limit pattern to specific extensions
Files []string `yaml:"files,omitempty" json:"files,omitempty"` // Optional: limit pattern to specific filenames
}
ContentRule represents a content-based detection pattern
func (*ContentRule) GetType ¶
func (c *ContentRule) GetType() string
GetType returns the content rule type, defaulting to "regex" if not specified
type Dependency ¶
type Dependency struct {
Type string `yaml:"type" json:"type"`
Name string `yaml:"name" json:"name"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Scope string `yaml:"scope,omitempty" json:"scope,omitempty"`
Direct bool `yaml:"direct" json:"direct"` // Direct (true) vs transitive (false) dependency
SourceFile string `yaml:"source_file,omitempty" json:"source_file,omitempty"` // Deprecated: use metadata.source instead
Metadata map[string]interface{} `yaml:"metadata,omitempty" json:"metadata,omitempty"` // Package-specific metadata (source, type, classifier, optional, exclusions, peer, etc.)
}
Dependency represents a dependency pattern (struct for YAML, but marshals as array for JSON)
func (*Dependency) Compile ¶
func (d *Dependency) Compile() (*CompiledDependency, error)
Compile compiles a dependency pattern to regex for performance
func (Dependency) MarshalJSON ¶
func (d Dependency) MarshalJSON() ([]byte, error)
MarshalJSON converts Dependency struct to array format [type, name, version, scope, direct, {metadata}] Format: 6 elements (always consistent) - [type, name, version, scope, direct, {metadata}] - scope: "prod", "dev", "test", "build", "optional", "peer", etc. (empty string if unknown) - direct: true (declared in manifest) or false (transitive) - metadata: optional object with source, type, classifier, exclusions, peer, optional, bundled, etc.
type Edge ¶
type Edge struct {
Target *Payload `json:"target"`
}
Edge represents a relationship between components and technologies
func (Edge) MarshalJSON ¶
MarshalJSON customizes Edge JSON serialization (target as ID string)
type File ¶
type File struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"` // "file" or "dir"
Size int64 `json:"size"`
Modified int64 `json:"modified"`
}
File represents a file or directory entry
type FileReader ¶
FileReader defines an interface for reading file content
type License ¶
type License struct {
LicenseName string `json:"license_name"` // Primary SPDX identifier (e.g., "MIT", "Apache-2.0")
DetectionType string `json:"detection_type"` // "direct", "normalized", "toml_parsed", "file_based"
SourceFile string `json:"source_file"` // Where detected (e.g., "package.json", "pyproject.toml")
Confidence float64 `json:"confidence"` // Detection confidence (0.0-1.0)
OriginalLicense string `json:"original_license,omitempty"` // Original license before normalization
}
License represents a structured license entity for knowledge graph integration
type Payload ¶
type Payload struct {
Metadata interface{} `json:"metadata,omitempty"`
Git *git.GitInfo `json:"git,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Path []string `json:"path"`
ComponentType string `json:"type,omitempty"` // Type of component (e.g., "maven", "nodejs", "python")
Tech []string `json:"tech"` // Changed from *string to []string to support multiple primary technologies
Techs []string `json:"techs"`
Languages map[string]int `json:"languages"`
PrimaryLanguages []PrimaryLanguage `json:"primary_languages,omitempty"` // Top programming languages (from code_stats)
Licenses []License `json:"licenses"` // Changed to structured License objects
Reason map[string][]string `json:"reason"` // Maps technology to detection reasons, "_" for non-tech reasons
Dependencies []Dependency `json:"dependencies"`
Properties map[string]interface{} `json:"properties,omitempty"`
Childs []*Payload `json:"childs"` // Changed from Children to Childs
Edges []Edge `json:"edges"`
ComponentRefs []ComponentRef `json:"component_refs,omitempty"` // Inter-component references (outgoing - components this component depends on)
CodeStats interface{} `json:"code_stats,omitempty"`
}
Payload represents the analysis result for a directory or component
func NewComponentPayload ¶
NewComponentPayload creates a payload for a component with common initialization pattern: - Calculates relative file path - Sets component type - Adds primary tech This eliminates the repetitive pattern found in all detectors.
func NewPayload ¶
NewPayload creates a new payload with a temporary ID (will be finalized by AssignIDs)
func NewPayloadWithPath ¶
NewPayloadWithPath creates a new payload with a single path (convenience function)
func (*Payload) AddDependency ¶
func (p *Payload) AddDependency(dep Dependency)
AddDependency adds a dependency with deduplication
func (*Payload) AddDockerReason ¶
AddDockerReason adds a Docker-related reason to the "_docker" key
func (*Payload) AddLanguage ¶
AddLanguage increments the count for a language
func (*Payload) AddLanguageWithCount ¶
AddLanguageWithCount increments the count for a language
func (*Payload) AddLicense ¶
AddLicense adds a license to the payload, deduplicating by name
func (*Payload) AddLicenseReason ¶
AddLicenseReason adds a license-related reason to the "_license" key
func (*Payload) AddPrimaryTech ¶
AddPrimaryTech adds a technology to the primary tech array (avoiding duplicates)
func (*Payload) AssignIDs ¶
AssignIDs assigns unique IDs to the entire payload tree. The root gets the provided ID (or generates random if empty), and all children get deterministic IDs based on the root ID + their relative path. This should be called once after the entire tree is built.
func (*Payload) DetectLanguage ¶
DetectLanguage detects the language from a file name using a LanguageDetector This is a convenience method that delegates to the language detector Deprecated: Use LanguageDetector directly for better modularity
func (*Payload) GetFullPath ¶
GetFullPath returns the full path as a string
func (*Payload) HasPrimaryTech ¶
HasPrimaryTech checks if a technology is in the primary tech array
func (*Payload) SetComponentProperties ¶
SetComponentProperties sets multiple properties for a component technology. Example: payload.SetComponentProperties("python", map[string]interface{}{"package_name": "myapp", "version": "1.0"})
func (*Payload) SetComponentProperty ¶
SetComponentProperty sets a property for a component technology. Standardizes on map[string]interface{} for flexibility while providing a clean API. Example: payload.SetComponentProperty("nodejs", "package_name", "@org/package")
func (*Payload) SetComponentType ¶
SetComponentType sets the component type (e.g., "maven", "nodejs", "python") This should be called by detectors to identify what kind of component this is
type PrimaryLanguage ¶
PrimaryLanguage represents a primary programming language (top languages by lines of code)
type Provider ¶
type Provider interface {
// ListDir returns the contents of a directory
ListDir(path string) ([]File, error)
// Open returns the content of a file
Open(path string) (string, error)
// Exists checks if a file or directory exists
Exists(path string) (bool, error)
// IsDir checks if a path is a directory
IsDir(path string) (bool, error)
// ReadFile reads file content as bytes
ReadFile(path string) ([]byte, error)
// GetBasePath returns the base path for this provider
GetBasePath() string
}
Provider defines the interface for file system operations
type Rule ¶
type Rule struct {
Tech string `yaml:"tech" json:"tech"`
Name string `yaml:"name" json:"name"`
Type string `yaml:"type" json:"type"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Properties map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
IsComponent *bool `yaml:"is_component,omitempty" json:"is_component,omitempty"` // nil = auto (use type-based logic)
IsPrimaryTech *bool `yaml:"is_primary_tech,omitempty" json:"is_primary_tech,omitempty"` // nil = use current logic (component = primary tech)
DotEnv []string `yaml:"dotenv,omitempty" json:"dotenv,omitempty"`
Dependencies []Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
Extensions []string `yaml:"extensions,omitempty" json:"extensions,omitempty"`
Content []ContentRule `yaml:"content,omitempty" json:"content,omitempty"`
}
Rule represents a technology detection rule
type TechInfo ¶
type TechInfo struct {
Name string `json:"name"`
Tech string `json:"tech"`
Category string `json:"category"`
Description string `json:"description,omitempty"`
IsPrimaryTech *bool `json:"is_primary_tech,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
}
TechInfo holds information about a technology