provider

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReservedName = "default"
)

Variables

This section is empty.

Functions

func NewProxiesParser

func NewProxiesParser(pdName string, tunnel C.Tunnel, filter string, excludeFilter string, excludeType string, dialerProxy string, override overrideSchema, ageSecretKey string) (resource.Parser[[]C.Proxy], error)

func ParseProxyProvider

func ParseProxyProvider(name string, mapping map[string]any, tunnel C.Tunnel) (P.ProxyProvider, error)

Types

type CompatibleProvider

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

CompatibleProvider for auto gc

func NewCompatibleProvider

func NewCompatibleProvider(name string, proxies []C.Proxy, hc *HealthCheck) (*CompatibleProvider, error)

func (*CompatibleProvider) Close

func (cp *CompatibleProvider) Close() error

func (CompatibleProvider) MarshalJSON

func (cp CompatibleProvider) MarshalJSON() ([]byte, error)

func (CompatibleProvider) Update

func (cp CompatibleProvider) Update() error

func (CompatibleProvider) VehicleType

func (cp CompatibleProvider) VehicleType() P.VehicleType

type HealthCheck

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

func NewHealthCheck

func NewHealthCheck(proxies []C.Proxy, url string, timeout uint, interval uint, lazy bool, expectedStatus utils.IntRanges[uint16]) *HealthCheck

type HealthCheckOption

type HealthCheckOption struct {
	URL      string
	Interval uint
}

type InlineProvider

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

InlineProvider for auto gc

func NewInlineProvider

func NewInlineProvider(name string, payload []map[string]any, parser resource.Parser[[]C.Proxy], hc *HealthCheck) (*InlineProvider, error)

func (*InlineProvider) Close

func (ip *InlineProvider) Close() error

func (InlineProvider) MarshalJSON

func (ip InlineProvider) MarshalJSON() ([]byte, error)

func (InlineProvider) Update

func (ip InlineProvider) Update() error

func (InlineProvider) VehicleType

func (ip InlineProvider) VehicleType() P.VehicleType

type OverrideExpr added in v1.1.2

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

OverrideExpr is an update-oriented subset of yq expressions for modifying a single proxy provider mapping. Configure it as an ordered string array; each item observes the result of all previous items:

proxy-providers:
  provider-name:
    override:
      override-expr:
        - '.name = "[provider] " + .name'
        - '.udp = true'
        - '.skip-cert-verify = false'
        - '.plugin-opts.mode = "tls"'
        - '.alpn[] |= upcase'
        - 'del(.password)'

Supported paths:

  • Root and mapping fields: ., .name, .plugin-opts.mode.
  • Quoted fields: ."field.with.dots" and .["field.with.dots"].
  • Array indexes, including negative indexes: .servers[0], .servers[-1].
  • Array or mapping wildcards: .alpn[] and .servers[].password.
  • Missing mappings and non-negative array indexes are created on assignment.
  • Reading through a scalar produces null; updating through one is a no-op.

Supported update statements:

  • Assignment: =. Its right side uses the root mapping as dot context.
  • Update assignment: |=. The right side receives the selected old value as its dot context, for example '.name |= upcase'.
  • Compound assignment: +=, -=, and *=.
  • Deletion: del(.field), del(.a, .b), and del(.items[].secret). del(.) is rejected because deleting the complete input cannot produce a mapping.
  • Conditional paths: '(select(.score > 5) | .tier) = "fast"'. A select that is false produces no match, so the assignment is skipped.
  • Statement pipelines: '.name |= trim | .name |= upcase'. A pipeline used as an assignment value must be parenthesized, for example '.name = (.name | upcase)' or '.name |= (trim | upcase)'. The same rule applies to and/or values.
  • Multi-result value pipelines. Wildcards, select, and comma unions may produce zero or more results; collect them with brackets, for example '.names = [.servers[] | select(.enabled) | .name]'. An assignment value that still has multiple uncollected results is rejected because a proxy provider override must produce one mapping.
  • A complete override-expr item may itself be a filter pipeline, for example '. | with_entries(.key |= upcase)'. Its final result must be exactly one mapping.

Supported value expressions:

  • null (null or ~), booleans, decimal/hex integers, floats, double-quoted strings, arrays, and mappings with double-quoted keys. String escapes follow yq: \n, \", and \\ are decoded; other backslash sequences remain literal. Arrays collect all item results; mapping values omit their key on zero results and keep the last of multiple results.
  • Path references, parentheses, and negative decimal integer/float literals.
  • Comma unions, for example '(.name, .port)'. A union after a wildcard follows yq stream ordering: each union branch processes all inputs.
  • yq string interpolation, for example '"[\(.type)] \(.name)"'. An interpolation expression with multiple results uses its first result.
  • A # outside a string starts a comment through the end of the expression item.
  • Arithmetic and collection operators: +, -, *, /, and %. '+' concatenates strings/arrays and shallow-merges mappings. '*' multiplies numbers, repeats strings, replaces arrays, and deep-merges mappings. '/' splits strings when both operands are strings.
  • Comparisons: ==, !=, <, <=, >, and >=. Equality follows yq scalar-value semantics and does not structurally compare arrays or mappings. Ordered comparisons support numbers, strings, and null.
  • Boolean/default operators: and, or, and //. Only false and null are falsey.

Supported functions use the current dot value as input:

  • Collection queries: length, keys, has, contains, and select. String length is measured in UTF-8 bytes. keys supports arrays/mappings; has accepts string mapping keys or positive/negative array indexes.
  • Array operations: reverse, sort, unique, flatten, any, and all. sort is limited to scalar arrays. flatten accepts an optional non-negative depth. any/all implement their zero-arg forms.
  • Stream/collection transforms: map, map_values, filter, to_entries, from_entries, with_entries, any_c, and all_c. map/filter/map_values accept arrays or mappings and operate on their values. map/filter return arrays; map_values preserves the input collection shape. to_entries accepts arrays/mappings and produces no result for null; from_entries accepts arrays of entries. from_entries requires string keys because the target configuration is map[string]any. with_entries therefore supports mappings only; any_c/all_c support arrays only.
  • String checks: test(pattern) and test(pattern, "g").
  • String transforms: sub, split, join, upcase, downcase, and trim. Like yq, sub replaces every regular-expression match. split produces no result for null; join accepts arrays.
  • Conversion/introspection: tostring, tonumber, type, and not.

Function arguments use yq-style comma separators. A semicolon is also accepted as an argument separator for compatibility with older expressions. Ordinary function arguments must not produce multiple results; map/filter-style expression arguments may produce streams. For example:

.name |= sub("^HK-(.*)$", "Hong Kong $1")
.tags |= split(",")
.options *= {"tls": {"enabled": true}, "retries": 3}

This intentionally does not implement the complete yq language. Variables, reduce, dynamic paths, recursive descent, document streams, file/environment access, custom tags, and yq CLI flags are not supported. Evaluation uses values instead of yq's mutable node references. Out-of-range reads do not extend source arrays, and flatten/map_values in a right-side filter do not mutate their source path; use |= to request an update. A right-side expression with no result leaves its target untouched instead of auto-creating a null value. Mapping streams, keys, and entry transforms use sorted keys because map[string]any does not retain YAML key order. Expressions are parsed while overrideSchema is decoded through encoding.TextUnmarshaler, so syntax errors are reported before providers run.

func NewOverrideExpr added in v1.1.2

func NewOverrideExpr(source string) (OverrideExpr, error)

NewOverrideExpr parses source into an OverrideExpr.

func (OverrideExpr) Apply added in v1.1.2

func (e OverrideExpr) Apply(mapping map[string]any) error

Apply applies the expression to mapping.

func (OverrideExpr) MarshalText added in v1.1.2

func (e OverrideExpr) MarshalText() ([]byte, error)

MarshalText returns the original expression text.

func (OverrideExpr) String added in v1.1.2

func (e OverrideExpr) String() string

String returns the original expression text.

func (*OverrideExpr) UnmarshalText added in v1.1.2

func (e *OverrideExpr) UnmarshalText(text []byte) error

UnmarshalText parses text into e.

type ProxySchema

type ProxySchema struct {
	Proxies []map[string]any `yaml:"proxies"`
}

type ProxySetProvider

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

ProxySetProvider for auto gc

func NewProxySetProvider

func NewProxySetProvider(name string, interval time.Duration, payload []map[string]any, parser resource.Parser[[]C.Proxy], vehicle P.Vehicle, hc *HealthCheck) (*ProxySetProvider, error)

func (*ProxySetProvider) Close

func (pp *ProxySetProvider) Close() error

func (ProxySetProvider) Initial

func (pp ProxySetProvider) Initial() error

func (ProxySetProvider) MarshalJSON

func (pp ProxySetProvider) MarshalJSON() ([]byte, error)

func (ProxySetProvider) Name

func (pp ProxySetProvider) Name() string

func (ProxySetProvider) Update

func (pp ProxySetProvider) Update() error

type SubscriptionInfo

type SubscriptionInfo struct {
	Upload   int64
	Download int64
	Total    int64
	Expire   int64
}

func NewSubscriptionInfo

func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo)

Jump to

Keyboard shortcuts

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