validators

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 19 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

This section is empty.

Functions

func BuildDetectionIndex

func BuildDetectionIndex(configs []ProviderConfig) ([]PrefixEntry, []PatternEntry, PrefixIndex)

func DetectProviderFromIndex

func DetectProviderFromIndex(key string, prefixes []PrefixEntry, patterns []PatternEntry, manualCategory string) string

func GetCategories added in v1.0.3

func GetCategories() ([]string, error)

func GetProviderGroups added in v1.0.3

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

func InitValidators

func InitValidators(proxy string, timeout int) (map[string]Validator, error)

Types

type DetectionResult added in v1.0.4

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

DetectionResult contains detection result with optional suggestions

func DetectProviderWithSuggestion added in v1.0.4

func DetectProviderWithSuggestion(key string, prefixes []PrefixEntry, patterns []PatternEntry, manualCategory string) DetectionResult

DetectProviderWithSuggestion detects provider and provides suggestions if detection fails

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) DetectProviderWithSuggestion added in v1.0.4

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

DetectProviderWithSuggestion returns detection result with suggestions if detection fails

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) *GenericValidator

func (*GenericValidator) KeyPatterns

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

func (*GenericValidator) Name

func (v *GenericValidator) Name() string

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"`
}

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"`
}

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 ProviderConfig

type ProviderConfig struct {
	Name                   string                  `yaml:"name"`
	Category               string                  `yaml:"category"`
	KeyPrefixes            []string                `yaml:"key_prefixes"`
	KeyPatterns            []string                `yaml:"key_patterns"`
	Validation             ValidationConfig        `yaml:"validation"`
	Metadata               []MetadataConfig        `yaml:"metadata"`
	MetadataFromValidation *MetadataFromValidation `yaml:"metadata_from_validation"`
}

func InitValidatorsWithConfigs

func InitValidatorsWithConfigs(proxy string, timeout int) (map[string]Validator, []ProviderConfig, 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 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"`
}

type Validator

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

Jump to

Keyboard shortcuts

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