router

package
v0.0.0-...-e105d0e Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetContextWithHeaderConfig

func SetContextWithHeaderConfig(ctx context.Context, config *RouterService) context.Context

func SetContextWithRouterConfig

func SetContextWithRouterConfig(ctx context.Context, config *RouterConfig) context.Context

Types

type CacheConfig

type CacheConfig struct {
	// Mode specifies the type of cache with two possible modes: simple and semantic.
	Mode string `json:"mode" default:"simple"`
	// TTL (Time To Live) is the duration for which cache entries should be considered valid.
	TTL time.Duration `json:"ttl"`
}

type PriorityRouter

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

func NewPriorityRouter

func NewPriorityRouter(providers []RouterConfig) *PriorityRouter

func (*PriorityRouter) Next

func (r *PriorityRouter) Next() (*RouterConfig, error)

type RetryConfig

type RetryConfig struct {
	// Number is the number of times to retry the request when a retryable
	Numbers int32 `json:"numbers" default:"1"`

	// RetryOnStatusCodes is a flat list of http response status codes that are
	// eligible for retry. This again should be feasible in any reasonable proxy.
	OnStatusCodes []uint32 `json:"on_status_codes" default:"[]"`
}

type RoundRobinRouter

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

func (*RoundRobinRouter) Iterator

func (r *RoundRobinRouter) Iterator() RouterIterator

func (*RoundRobinRouter) Next

func (r *RoundRobinRouter) Next() *RouterConfig

type RouterConfig

type RouterConfig struct {
	Name       string         `json:"name"`
	Auth       map[string]any `json:"auth"`
	VirtualKey string         `json:"virtual_key"`
	Retry      RetryConfig    `json:"retry"`
	Cache      CacheConfig    `json:"cache"`
	Strategy   StrategyConfig `json:"strategy"`
	Targets    []RouterConfig `json:"targets"`
	Metadata   map[string]any `json:"metadata"`
}

func GetContextWithRouterConfig

func GetContextWithRouterConfig(ctx context.Context) *RouterConfig

func NewRouterConfig

func NewRouterConfig(config string, headers http.Header) (*RouterConfig, error)

type RouterConfigContextKey

type RouterConfigContextKey struct{}

type RouterIterator

type RouterIterator interface {
	Next() *RouterConfig
}

func NewRoundRobinRouter

func NewRoundRobinRouter(providers []RouterConfig) RouterIterator

func NewRouterService

func NewRouterService(root *RouterConfig) RouterIterator

type RouterService

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

func GetContextWithHeaderConfig

func GetContextWithHeaderConfig(ctx context.Context) *RouterService

func (*RouterService) HasNext

func (rc *RouterService) HasNext() bool

func (*RouterService) Iterator

func (rc *RouterService) Iterator() RouterIterator

func (*RouterService) Next

func (rc *RouterService) Next() *RouterConfig

type RouterServiceContextKey

type RouterServiceContextKey struct{}

type Strategy

type Strategy string
const (
	Priority Strategy = "priority"
)
const (
	RoundRobin Strategy = "roundrobin"
)

type StrategyConfig

type StrategyConfig struct {
	Mode string `json:"mode"`
}

Jump to

Keyboard shortcuts

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