Documentation
¶
Overview ¶
Package filtering provides server filtering capabilities for registry data.
This package implements a comprehensive filtering system that allows the registry API to selectively include or exclude servers based on name patterns and tags. The filtering system supports both include and exclude rules with exclude taking precedence over include.
Architecture ¶
The filtering system consists of three main components:
- NameFilter: Handles server name filtering using glob patterns
- TagFilter: Handles tag-based filtering using exact string matching
- FilterService: Coordinates both name and tag filtering
Name Filtering ¶
Name filtering uses Go's filepath.Match for glob pattern matching, supporting wildcards like '*', '?', and character classes '[...]'. Examples:
- "postgres-*" matches "postgres-server", "postgres-client"
- "db?" matches "db1", "db2" but not "database"
- "server[1-3]" matches "server1", "server2", "server3"
Tag Filtering ¶
Tag filtering uses exact string matching against server tags. A server is included if any of its tags match any include tag, and excluded if any of its tags match any exclude tag.
Filtering Logic ¶
Both name and tag filters follow the same precedence rules:
- If exclude patterns/tags are specified and match -> exclude (precedence)
- If include patterns/tags are specified and match -> include
- If include patterns/tags are specified but no match -> exclude
- If only exclude patterns/tags specified and no match -> include
- If no filters specified -> include (default behavior)
For a server to be included in the final registry, it must pass BOTH name and tag filtering (logical AND).
Usage Example ¶
service := NewDefaultFilterService()
filter := &config.FilterConfig{
Names: &config.NameFilterConfig{
Include: []string{"postgres-*", "mysql-*"},
Exclude: []string{"*-experimental"},
},
Tags: &config.TagFilterConfig{
Include: []string{"database", "sql"},
Exclude: []string{"deprecated"},
},
}
filteredRegistry, err := service.ApplyFilters(ctx, originalRegistry, filter)
Detailed Logging ¶
The filtering system provides detailed logging with specific reasons for inclusion or exclusion decisions, making it easy to debug filtering configurations and understand filtering behavior.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FilterService ¶
type FilterService interface {
// ApplyFilters filters the registry based on filter configuration
ApplyFilters(
ctx context.Context,
reg *toolhivetypes.UpstreamRegistry,
filter *config.FilterConfig,
) (*toolhivetypes.UpstreamRegistry, error)
}
FilterService coordinates name and tag filtering to apply registry filters
func NewDefaultFilterService ¶
func NewDefaultFilterService() FilterService
NewDefaultFilterService creates a new defaultFilterService with default filter implementations
func NewFilterService ¶
func NewFilterService(nameFilter NameFilter, tagFilter TagFilter) FilterService
NewFilterService creates a new defaultFilterService with custom filter implementations
type NameFilter ¶
type NameFilter interface {
// ShouldInclude determines if a server name should be included based on include/exclude patterns
// Returns (shouldInclude bool, reason string)
ShouldInclude(name string, include, exclude []string) (bool, string)
}
NameFilter handles name-based filtering using glob patterns
func NewDefaultNameFilter ¶
func NewDefaultNameFilter() NameFilter
NewDefaultNameFilter creates a new defaultNameFilter
type TagFilter ¶
type TagFilter interface {
// ShouldInclude determines if a server with given tags should be included based on include/exclude tag lists
// Returns (shouldInclude bool, reason string)
ShouldInclude(tags []string, include, exclude []string) (bool, string)
}
TagFilter handles tag-based filtering using exact string matching
func NewDefaultTagFilter ¶
func NewDefaultTagFilter() TagFilter
NewDefaultTagFilter creates a new defaultTagFilter