validators

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CustomProvidersDir string
)

Functions

func GetCategories added in v1.0.3

func GetCategories() ([]string, error)

func GetCommonDomains added in v1.0.8

func GetCommonDomains() []string

func GetProviderGroups added in v1.0.3

func GetProviderGroups() (map[string][]ProviderInfo, error)

func NewValidatorFactory added in v1.0.8

func NewValidatorFactory(proxy string, timeout int) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)

func NewValidatorFactoryWithOptions added in v1.2.0

func NewValidatorFactoryWithOptions(proxy string, timeout int, opts FactoryOptions) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)

NewValidatorFactoryWithOptions is the configurable constructor. opts.PersistentCachePath enables a cross-run positive cache; opts.DisableCache forces every request through the network regardless of either cache layer.

Types

type DetectionResult added in v1.0.4

type DetectionResult struct {
	Provider    string
	Suggestions []string
	Message     string
	Entropy     float64
}

func DetectProviderWithSuggestion added in v1.0.4

func DetectProviderWithSuggestion(key string, idx *DetectorIndex, manualCategory string) DetectionResult

type Detector

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

func NewDetector

func NewDetector() *Detector

func NewDetectorFromConfigs

func NewDetectorFromConfigs(configs []ProviderConfig) *Detector

func (*Detector) DetectProvider

func (d *Detector) DetectProvider(apiKey string, manualCategory string) string

func (*Detector) DetectProviderBytes added in v1.1.0

func (d *Detector) DetectProviderBytes(apiKey []byte, manualCategory string) string

func (*Detector) DetectProviderWithSuggestion added in v1.0.4

func (d *Detector) DetectProviderWithSuggestion(apiKey string, manualCategory string) DetectionResult

type DetectorIndex added in v1.0.7

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

func BuildDetectionIndex

func BuildDetectionIndex(configs []ProviderConfig) *DetectorIndex

type EndpointConfig added in v1.0.9

type EndpointConfig struct {
	URL     string            `yaml:"url"`
	Region  string            `yaml:"region,omitempty"`
	Headers map[string]string `yaml:"headers,omitempty"`
}

type ErrorCheck added in v1.0.9

type ErrorCheck struct {
	JSONPath string `yaml:"json_path,omitempty"`
}

type FactoryOptions added in v1.2.0

type FactoryOptions struct {
	// PersistentCachePath enables the cross-run positive cache when non-empty.
	// When empty, the factory uses only the in-memory ValidationCache.
	PersistentCachePath string
	// PersistentCacheTTL is the freshness window for persistent entries.
	// Zero means use the default (5 minutes).
	PersistentCacheTTL time.Duration
	// DisableCache disables both layers; validators will always hit the
	// network. Used when the user passes --no-cache.
	DisableCache bool
}

FactoryOptions configures the optional layers attached to a ValidatorFactory.

type FailureWhen added in v1.2.0

type FailureWhen struct {
	BodyRegex     string `yaml:"body_regex,omitempty"`
	BodyJSONPath  string `yaml:"body_jsonpath,omitempty"`
	JSONPathValue string `yaml:"jsonpath_value,omitempty"`
}

type GenericValidator

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

func NewGenericValidator

func NewGenericValidator(cfg ProviderConfig, proxy string, timeout int) (*GenericValidator, error)

func NewGenericValidatorWithClient

func NewGenericValidatorWithClient(cfg ProviderConfig, httpClient *http.Client, limiter *client.RateLimiterManager) *GenericValidator

func (*GenericValidator) FetchMetadata added in v1.0.9

func (v *GenericValidator) FetchMetadata(ctx context.Context, apiKey string, result *models.ValidationResult)

func (*GenericValidator) KeyPatterns

func (v *GenericValidator) KeyPatterns() []string

func (*GenericValidator) Name

func (v *GenericValidator) Name() string

func (*GenericValidator) SetCache added in v1.0.9

func (v *GenericValidator) SetCache(cache client.ResultCache)

func (*GenericValidator) SetCanaryCheck added in v1.0.8

func (v *GenericValidator) SetCanaryCheck(check bool)

func (*GenericValidator) SetSkipMetadata added in v1.0.8

func (v *GenericValidator) SetSkipMetadata(skip bool)

func (*GenericValidator) Validate

func (v *GenericValidator) Validate(ctx context.Context, apiKey string) (*models.ValidationResult, error)

type MetadataConfig

type MetadataConfig struct {
	URL               string            `yaml:"url"`
	Method            string            `yaml:"method"`
	Auth              string            `yaml:"auth"`
	Headers           map[string]string `yaml:"headers"`
	BalancePath       string            `yaml:"balance_path"`
	Extract           string            `yaml:"extract"`
	StoreAs           string            `yaml:"store_as"`
	RegexExtract      string            `yaml:"regex_extract"`
	RegexExtractMatch int               `yaml:"regex_extract_match"`
}

type MetadataFromValidation

type MetadataFromValidation struct {
	BalancePath         string `yaml:"balance_path"`
	BalanceSubtractPath string `yaml:"balance_subtract_path"`
	NamePath            string `yaml:"name_path"`
	NameFallbackPath    string `yaml:"name_fallback_path"`
	EmailPath           string `yaml:"email_path"`
	QuotaPath           string `yaml:"quota_path"`
	CreditsPath         string `yaml:"credits_path"`
	VIPLevelPath        string `yaml:"vip_level_path"`
	TeamNamePath        string `yaml:"team_name_path"`
	UsernamePath        string `yaml:"username_path"`
	RegexExtract        string `yaml:"regex_extract"`
	RegexExtractMatch   int    `yaml:"regex_extract_match"`
}

type PatternEntry

type PatternEntry struct {
	Regex    *regexp.Regexp
	Provider string
	Category string
}

type PrefixEntry

type PrefixEntry struct {
	Prefix   string
	Provider string
	Category string
}

type PrefixIndex added in v1.0.5

type PrefixIndex map[string][]PrefixEntry

type PrefixTrie added in v1.1.0

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

func NewPrefixTrie added in v1.1.0

func NewPrefixTrie() *PrefixTrie

func (*PrefixTrie) Add added in v1.1.0

func (t *PrefixTrie) Add(p *PrefixEntry)

func (*PrefixTrie) Build added in v1.1.0

func (t *PrefixTrie) Build()

func (*PrefixTrie) Search added in v1.1.0

func (t *PrefixTrie) Search(key string) []*PrefixEntry

type ProviderConfig

type ProviderConfig struct {
	Name                   string                  `yaml:"name"`
	Category               string                  `yaml:"category"`
	KeyPrefixes            []string                `yaml:"key_prefixes"`
	KeyPatterns            []string                `yaml:"key_patterns"`
	SyntaxCheck            string                  `yaml:"syntax_check,omitempty"`
	CanaryPatterns         []string                `yaml:"canary_patterns,omitempty"`
	Validation             ValidationConfig        `yaml:"validation"`
	Metadata               []MetadataConfig        `yaml:"metadata,omitempty"`
	MetadataFromValidation *MetadataFromValidation `yaml:"metadata_from_validation,omitempty"`
	IsCustom               bool                    `yaml:"-"`
}

func InitValidatorsWithConfigs

func InitValidatorsWithConfigs(proxy string, timeout int) (map[string]Validator, []ProviderConfig, *client.ProxyRotator, error)

func LoadProviderConfigs

func LoadProviderConfigs() ([]ProviderConfig, error)

type ProviderGroup added in v1.0.3

type ProviderGroup struct {
	Prefix    string
	Providers []ProviderInfo
}

type ProviderInfo

type ProviderInfo struct {
	Name        string
	Category    string
	KeyPrefixes []string
}

func FindProviderByName added in v1.0.3

func FindProviderByName(name string) ([]ProviderInfo, error)

func GetAllProviders

func GetAllProviders() ([]ProviderInfo, error)

func GetProvidersByCategory added in v1.0.3

func GetProvidersByCategory(category string) ([]ProviderInfo, error)

type ResponseMatch added in v1.2.0

type ResponseMatch struct {
	BodyRegex      string `yaml:"body_regex,omitempty"`
	BodyJSONPath   string `yaml:"body_jsonpath,omitempty"`
	JSONPathValue  string `yaml:"jsonpath_value,omitempty"`
	HeaderContains string `yaml:"header_contains,omitempty"`
}

type TrieNode added in v1.1.0

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

type ValidationConfig

type ValidationConfig struct {
	Method         string            `yaml:"method"`
	URL            string            `yaml:"url"`
	Auth           string            `yaml:"auth"`
	Headers        map[string]string `yaml:"headers"`
	Body           string            `yaml:"body"`
	Endpoints      []EndpointConfig  `yaml:"endpoints,omitempty"`
	ErrorCheck     *ErrorCheck       `yaml:"error_check,omitempty"`
	ExpectedStatus []int             `yaml:"expected_status,omitempty"`
	ResponseMatch  *ResponseMatch    `yaml:"response_match,omitempty"`
	RetryOnStatus  []int             `yaml:"retry_on_status,omitempty"`
	FailureWhen    *FailureWhen      `yaml:"failure_when,omitempty"`
}

type Validator

type Validator interface {
	Name() string
	KeyPatterns() []string
	Validate(ctx context.Context, apiKey string) (*models.ValidationResult, error)
	SetSkipMetadata(bool)
	SetCanaryCheck(bool)
	FetchMetadata(ctx context.Context, apiKey string, result *models.ValidationResult)
}

type ValidatorFactory added in v1.0.8

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

func (*ValidatorFactory) Cache added in v1.0.9

func (f *ValidatorFactory) Cache() client.ResultCache

func (*ValidatorFactory) GetValidator added in v1.0.8

func (f *ValidatorFactory) GetValidator(name string) (Validator, bool)

func (*ValidatorFactory) SharedClient added in v1.1.0

func (f *ValidatorFactory) SharedClient() *http.Client

func (*ValidatorFactory) SharedLimiter added in v1.2.0

func (f *ValidatorFactory) SharedLimiter() *client.RateLimiterManager

SharedLimiter exposes the underlying RateLimiterManager so callers can install a global rate ceiling via SetGlobalLimit.

Jump to

Keyboard shortcuts

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