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 DefaultFilterService ¶
type DefaultFilterService struct {
// contains filtered or unexported fields
}
DefaultFilterService implements filtering coordination using name and tag filters
func NewDefaultFilterService ¶
func NewDefaultFilterService() *DefaultFilterService
NewDefaultFilterService creates a new DefaultFilterService with default filter implementations
func NewFilterService ¶
func NewFilterService(nameFilter NameFilter, tagFilter TagFilter) *DefaultFilterService
NewFilterService creates a new DefaultFilterService with custom filter implementations
func (*DefaultFilterService) ApplyFilters ¶
func (s *DefaultFilterService) ApplyFilters( ctx context.Context, reg *toolhivetypes.Registry, filter *config.FilterConfig) (*toolhivetypes.Registry, error)
ApplyFilters filters the registry based on filter configuration
The filtering process: 1. If no filter is specified, return the original registry unchanged 2. Create a new registry with the same metadata but empty server maps 3. For each server (both container and remote), apply name and tag filtering 4. Only include servers that pass both name and tag filters 5. Return the filtered registry
type DefaultNameFilter ¶
type DefaultNameFilter struct{}
DefaultNameFilter implements name filtering using Go's filepath.Match for glob patterns
func NewDefaultNameFilter ¶
func NewDefaultNameFilter() *DefaultNameFilter
NewDefaultNameFilter creates a new DefaultNameFilter
func (*DefaultNameFilter) ShouldInclude ¶
func (*DefaultNameFilter) ShouldInclude(name string, include, exclude []string) (bool, string)
ShouldInclude determines if a server name should be included based on include/exclude patterns
Logic: 1. If exclude patterns are specified and name matches any exclude pattern -> exclude (exclude takes precedence) 2. If include patterns are specified and name matches any include pattern -> include 3. If include patterns are specified and name doesn't match any -> exclude 4. If only exclude patterns are specified (no include) and name doesn't match exclude -> include 5. If no patterns are specified -> include (default behavior)
type DefaultTagFilter ¶
type DefaultTagFilter struct{}
DefaultTagFilter implements tag filtering using exact string matching
func NewDefaultTagFilter ¶
func NewDefaultTagFilter() *DefaultTagFilter
NewDefaultTagFilter creates a new DefaultTagFilter
func (*DefaultTagFilter) ShouldInclude ¶
func (*DefaultTagFilter) ShouldInclude(tags []string, include, exclude []string) (bool, string)
ShouldInclude determines if a server with given tags should be included based on include/exclude tag lists
Logic: 1. If exclude tags are specified and any server tag matches any exclude tag -> exclude (exclude takes precedence) 2. If include tags are specified and any server tag matches any include tag -> include 3. If include tags are specified and no server tags match any include tag -> exclude 4. If only exclude tags are specified (no include) and no server tags match exclude -> include 5. If no tag filters are specified -> include (default behavior)
type FilterService ¶
type FilterService interface {
// ApplyFilters filters the registry based on filter configuration
ApplyFilters(ctx context.Context, reg *toolhivetypes.Registry, filter *config.FilterConfig) (*toolhivetypes.Registry, error)
}
FilterService coordinates name and tag filtering to apply registry filters
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
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