index

package
v3.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IndexFileName is the name of the persistent cache file.
	IndexFileName = "index.gob"

	// IndexVersion is the schema version for cache invalidation on breaking
	// changes.
	IndexVersion = 1

	// DefaultMaxSize is the default maximum number of templates to cache.
	DefaultMaxSize = 50000

	// DefaultMaxWeight is the default maximum weight of the cache.
	DefaultMaxWeight = DefaultMaxSize * 800 // ~40MB assuming ~800B/entry
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// Authors to include.
	Authors []string

	// Tags to include.
	Tags []string

	// ExcludeTags to exclude (takes precedence over Tags).
	ExcludeTags []string

	// IncludeTags to force include even if excluded.
	IncludeTags []string

	// IDs to include (supports wildcards, OR logic).
	IDs []string

	// ExcludeIDs to exclude (supports wildcards).
	ExcludeIDs []string

	// IncludeTemplates paths to force include even if excluded.
	IncludeTemplates []string

	// ExcludeTemplates paths to exclude.
	ExcludeTemplates []string

	// Severities to include.
	Severities []severity.Severity

	// ExcludeSeverities to exclude.
	ExcludeSeverities []severity.Severity

	// ProtocolTypes to include.
	ProtocolTypes []types.ProtocolType

	// ExcludeProtocolTypes to exclude.
	ExcludeProtocolTypes []types.ProtocolType
}

Filter represents filtering criteria for template metadata.

Inclusion fields (e.g., Authors, Tags, IDs, Severities, ProtocolTypes) use AND logic across different filter types and OR logic within each type. Exclusion fields (e.g., ExcludeTags, ExcludeIDs, ExcludeSeverities, ExcludeProtocolTypes) take precedence over inclusion fields. Additionally, IncludeTemplates and IncludeTags can force inclusion of templates even if they match exclusion criteria.

func UnmarshalFilter

func UnmarshalFilter(
	authors, tags, excludeTags, includeTags []string,
	ids, excludeIDs []string,
	includeTemplates, excludeTemplates []string,
	severities, excludeSeverities []string,
	protocolTypes, excludeProtocolTypes []string,
) (*Filter, error)

UnmarshalFilter creates a Filter from nuclei options.

func (*Filter) IsEmpty

func (f *Filter) IsEmpty() bool

IsEmpty returns true if filter has no criteria set.

func (*Filter) Matches

func (f *Filter) Matches(m *Metadata) bool

Matches checks if metadata matches the filter criteria.

func (*Filter) String

func (f *Filter) String() string

String returns a human-readable representation of the filter.

type FilterFunc

type FilterFunc func(*Metadata) bool

FilterFunc is a function that filters metadata.

func UnmarshalFilterFunc

func UnmarshalFilterFunc(filter *Filter) FilterFunc

UnmarshalFilterFunc creates a FilterFunc from filter criteria.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index represents a cache for template metadata.

func NewDefaultIndex

func NewDefaultIndex() (*Index, error)

NewDefaultIndex creates a index with default settings in the default cache directory.

func NewIndex

func NewIndex(cacheDir string) (*Index, error)

NewIndex creates a new template metadata cache with the given options.

func (*Index) All

func (i *Index) All() []string

All returns all template paths in the index.

func (*Index) Clear

func (i *Index) Clear()

Clear removes all cached entries.

func (*Index) Count

func (i *Index) Count(filter *Filter) int

Count returns the number of templates matching the filter.

func (*Index) Delete

func (i *Index) Delete(path string)

Delete removes metadata for a path.

func (*Index) Filter

func (i *Index) Filter(filter *Filter) []string

Filter returns all template paths that match the given filter criteria.

func (*Index) FilterFunc

func (i *Index) FilterFunc(fn FilterFunc) []string

FilterFunc returns all template paths that match the given filter function.

func (*Index) Get

func (i *Index) Get(path string) (*Metadata, bool)

Get retrieves metadata for a template path, validating freshness via mtime.

func (*Index) GetAll

func (i *Index) GetAll() map[string]*Metadata

GetAll returns all metadata entries in the index.

func (*Index) Has

func (i *Index) Has(path string) bool

Has checks if metadata exists for a path without validation.

func (*Index) Load

func (i *Index) Load() error

Load loads the cache from disk using gob decoding.

func (*Index) Save

func (i *Index) Save() error

Save persists the cache to disk using gob encoding.

func (*Index) Set

func (i *Index) Set(path string, metadata *Metadata) (*Metadata, bool)

Set stores metadata for a template path.

The caller is responsible for ensuring the metadata is valid and contains the correct checksum before calling this method. Use [SetFromTemplate] for automatic extraction and checksum computation.

Returns the metadata and whether it was successfully cached (false if evicted).

func (*Index) SetFromTemplate

func (i *Index) SetFromTemplate(path string, tpl *templates.Template) (*Metadata, bool)

SetFromTemplate extracts metadata from a parsed template and stores it.

Returns the metadata and whether it was successfully cached. The metadata is always returned (even on checksum failure) for immediate filtering use. Returns false if the metadata was not cached (e.g., set, evicted).

func (*Index) Size

func (i *Index) Size() int

Size returns the number of cached entries.

type Metadata

type Metadata struct {
	// ID is the unique identifier of the template.
	ID string `gob:"id"`

	// FilePath is the path to the template file.
	FilePath string `gob:"file_path"`

	// ModTime is the modification time of the template file.
	ModTime time.Time `gob:"mod_time"`

	// Name is the name of the template.
	Name string `gob:"name"`

	// Authors are the authors of the template.
	Authors []string `gob:"authors"`

	// Tags are the tags associated with the template.
	Tags []string `gob:"tags"`

	// Severity is the severity level of the template.
	Severity string `gob:"severity"`

	// ProtocolType is the primary protocol type of the template.
	ProtocolType string `gob:"protocol_type"`

	// Verified indicates whether the template is verified.
	Verified bool `gob:"verified"`

	// TemplateVerifier is the verifier used for the template.
	TemplateVerifier string `gob:"verifier,omitempty"`
}

Metadata contains lightweight metadata extracted from a template.

func NewMetadataFromTemplate

func NewMetadataFromTemplate(path string, tpl *templates.Template) *Metadata

NewMetadataFromTemplate creates a new metadata object from a template.

func (*Metadata) HasAuthor

func (m *Metadata) HasAuthor(author string) bool

HasAuthor checks if the metadata contains the given author.

func (*Metadata) HasTag

func (m *Metadata) HasTag(tag string) bool

HasTag checks if the metadata contains the given tag.

func (*Metadata) IsValid

func (m *Metadata) IsValid() bool

IsValid checks if the cached metadata is still valid by comparing the file modification time.

func (*Metadata) MatchesProtocol

func (m *Metadata) MatchesProtocol(protocolType types.ProtocolType) bool

MatchesProtocol checks if the metadata matches the given protocol type.

func (*Metadata) MatchesSeverity

func (m *Metadata) MatchesSeverity(sev severity.Severity) bool

MatchesSeverity checks if the metadata matches the given severity.

Jump to

Keyboard shortcuts

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