cfg

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequiredField is an error for required field.
	ErrRequiredField = errors.New("required field is empty")
	// ErrDenyInterval is an error for deny interval, too short or too long.
	ErrDenyInterval = errors.New("deny interval")
	// ErrDuplicate is an error for duplicated value.
	ErrDuplicate = errors.New("duplicate error")
	// ErrParse is an error for parsing error.
	ErrParse = errors.New("parse error")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host      string       `json:"host"`
	Port      uint16       `json:"port"`
	UserAgent string       `json:"user_agent"`
	Timeout   Duration     `json:"timeout"`
	Root      string       `json:"root"`
	Retries   uint8        `json:"retries"`
	Limiter   LimitOptions `json:"limiter"`
	Debug     bool         `json:"debug"`
	Groups    []Group      `json:"groups"`
}

Config is a main configuration structure.

func New

func New(filename string) (*Config, error)

New creates a new configuration from a file.

func (*Config) Addr

func (c *Config) Addr() string

Addr returns service's net address.

func (*Config) GroupsEndpoints added in v1.1.4

func (c *Config) GroupsEndpoints() map[string]*Group

GroupsEndpoints returns a map of groups by their endpoints.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for correctness.

type Duration

type Duration time.Duration

Duration is a wrapper around time.Duration that supports unmarshalling from a JSON string.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the Duration type.

func (*Duration) String

func (d *Duration) String() string

String returns a string representation of the Duration type.

func (*Duration) Timed

func (d *Duration) Timed() time.Duration

Timed returns a time.Duration value of the Duration type.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON parses a JSON string into a Duration type.

type Group

type Group struct {
	Name          string         `json:"name"`
	Endpoint      string         `json:"endpoint"`
	Encoded       bool           `json:"encoded"`
	Period        Duration       `json:"period"`
	Subscriptions []Subscription `json:"subscriptions"`
}

Group is a collection of subscriptions.

func (*Group) MaxSubscriptionTimeout added in v1.0.3

func (g *Group) MaxSubscriptionTimeout() time.Duration

MaxSubscriptionTimeout returns the maximum timeout of all subscriptions in the group.

func (*Group) Validate

func (g *Group) Validate(root string) error

Validate checks the group for correctness.

type LimitOptions added in v1.8.0

type LimitOptions struct {
	MaxConcurrent uint32   `json:"max_concurrent"`
	Rate          float64  `json:"rate"`
	Burst         float64  `json:"burst"`
	Interval      Duration `json:"interval"`
	CleanInterval Duration `json:"clean_interval"`
	Exclude       []string `json:"exclude"`
	// contains filtered or unexported fields
}

LimitOptions is a rate limiter configuration.

func (*LimitOptions) ExcludedIPS added in v1.8.0

func (l *LimitOptions) ExcludedIPS() map[string]struct{}

ExcludedIPS returns a map of excluded IPs.

func (*LimitOptions) Validate added in v1.8.0

func (l *LimitOptions) Validate() error

Validate checks the rate limiter options for correctness.

type Prefixes added in v1.2.0

type Prefixes []string

Prefixes is a list of prefixes for filtering subscription's values.

func (Prefixes) LogValue added in v1.2.0

func (prefixes Prefixes) LogValue() slog.Value

LogValue returns a slog.Value to implement slog.LogValuer interface.

func (Prefixes) Match added in v1.2.2

func (prefixes Prefixes) Match(subURL string) bool

Match checks if the subscription proxy SubPath has prefixes.

type SubPath added in v1.3.0

type SubPath string

SubPath is a subscription Path or file path string type.

func (SubPath) LogValue added in v1.3.0

func (su SubPath) LogValue() slog.Value

LogValue returns a slog.Value to implement slog.LogValuer interface.

func (SubPath) String added in v1.3.0

func (su SubPath) String() string

String returns a string representation of the SubPath type.

type Subscription

type Subscription struct {
	Name        string   `json:"name"`
	Path        SubPath  `json:"url"`
	Encoded     bool     `json:"encoded"`
	Timeout     Duration `json:"timeout"`
	HasPrefixes Prefixes `json:"has_prefixes"`
	Local       bool     `json:"local"`
}

Subscription represents a subscription data.

func (*Subscription) Filter added in v1.2.1

func (s *Subscription) Filter(subURLs []string) []string

Filter returns a list of URLs filtered by prefixes.

func (*Subscription) Validate

func (s *Subscription) Validate(root string) error

Validate checks the subscription for correctness.

Jump to

Keyboard shortcuts

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