service

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMongoClient

func NewMongoClient(ctx context.Context, uri string) (*mongo.Client, error)

func NewRedisClient

func NewRedisClient(ctx context.Context, uri string) (*redis.Client, error)

Types

type BackendService

type BackendService struct {
	Name               string             `json:"name" yaml:"name"`
	Scheme             string             `json:"scheme" yaml:"scheme"`
	UpstreamTargets    []string           `json:"upstreamTargets" yaml:"upstreamTargets"`
	Path               string             `json:"path,omitempty" yaml:"path,omitempty"`
	Domain             string             `json:"domain" yaml:"domain"`
	HealthCheck        string             `json:"healthCheck" yaml:"healthCheck"`
	RetryAttempts      int                `json:"retryAttempts,omitempty" yaml:"retryAttempts,omitempty"`
	Timeout            time.Duration      `json:"timeout" yaml:"timeout"`
	MaxIdleConns       int                `json:"maxIdleConns,omitempty" yaml:"maxIdleConns,omitempty"`
	MaxIdleTime        time.Duration      `json:"maxIdleTime" yaml:"maxIdleTime"`
	StripPath          bool               `json:"stripPath,omitempty" yaml:"stripPath,omitempty"`
	AuthConfig         *config.AuthConfig `json:"auth,omitempty" yaml:"auth,omitempty"`
	LoadBalancerPolicy LoadBalancerPolicy `json:"loadBalancerPolicy,omitempty" yaml:"loadBalancerPolicy,omitempty"`
	RewriteMatch       string             `json:"rewriteMatch,omitempty" yaml:"rewriteMatch,omitempty"`
	RewriteReplace     string             `json:"rewriteReplace,omitempty" yaml:"rewriteReplace,omitempty"`
	// contains filtered or unexported fields
}

BackendService holds the details of a backend service

func (*BackendService) GetCompiledRewriteMatch added in v0.0.32

func (bs *BackendService) GetCompiledRewriteMatch() *regexp.Regexp

GetCompiledRewriteMatch returns the compiled rewrite match regular expression for the backend service.

func (*BackendService) GetHealthCheck

func (bs *BackendService) GetHealthCheck() bool

GetHealthCheck performs a health check on the backend service and returns true if it is healthy.

func (*BackendService) GetHttpClient added in v0.0.33

func (bs *BackendService) GetHttpClient() *http.Client

func (*BackendService) GetLoadBalancer added in v0.0.26

func (bs *BackendService) GetLoadBalancer() loadbalancer.LoadBalancer

func (*BackendService) GetTokenValidator added in v0.0.14

func (bs *BackendService) GetTokenValidator() auth.TokenValidator

func (*BackendService) GetUserDataHeader added in v0.0.14

func (bs *BackendService) GetUserDataHeader() string

func (*BackendService) Init added in v0.0.26

func (bs *BackendService) Init()

type ErrServiceExists

type ErrServiceExists struct {
	Name string
}

func (ErrServiceExists) Error

func (e ErrServiceExists) Error() string

type ErrServiceNotFound

type ErrServiceNotFound struct {
	Name string
}

func (ErrServiceNotFound) Error

func (e ErrServiceNotFound) Error() string

type ErrUnsupportedServiceType added in v0.0.29

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

func (ErrUnsupportedServiceType) Error added in v0.0.29

type LoadBalancerPolicy

type LoadBalancerPolicy struct {
	Type    string        `json:"type" yaml:"type"`
	Options PolicyOptions `json:"options,omitempty" yaml:"options,omitempty"`
}

type MemoryServiceRegistry

type MemoryServiceRegistry struct {
	Services map[string]*BackendService
	// contains filtered or unexported fields
}

MemoryServiceRegistry is an in-memory implementation of the ServiceRegistry interface

func NewMemoryServiceRegistry

func NewMemoryServiceRegistry(br *baseRegistry) *MemoryServiceRegistry

NewMemoryServiceRegistry creates a new MemoryServiceRegistry instance

func (*MemoryServiceRegistry) AddService

func (r *MemoryServiceRegistry) AddService(service *BackendService) error

AddService adds a new backend service

func (*MemoryServiceRegistry) GetServices

func (r *MemoryServiceRegistry) GetServices() []*BackendService

GetServices retrieves all backend services

func (MemoryServiceRegistry) GetTrie added in v0.0.30

func (r MemoryServiceRegistry) GetTrie() *RoutingTrie

func (*MemoryServiceRegistry) RemoveService

func (r *MemoryServiceRegistry) RemoveService(name string) error

RemoveService removes a backend service by name

func (*MemoryServiceRegistry) UpdateService

func (r *MemoryServiceRegistry) UpdateService(service *BackendService) error

UpdateService updates an existing backend service

type PolicyOptions

type PolicyOptions struct {
	Weights []int `json:"weights,omitempty" yaml:"weights,omitempty"`
}

type RedisRegistry

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

RedisRegistry implements the ServiceRegistry interface using Redis as a backend storage

func NewRedisRegistry

func NewRedisRegistry(ctx context.Context, redisClient *redis.Client, namespace string, br *baseRegistry) (*RedisRegistry, error)

NewRedisRegistry creates a new RedisRegistry instance with a Redis client connection

func (*RedisRegistry) AddService

func (r *RedisRegistry) AddService(service *BackendService) error

AddService adds a new backend service to Redis

func (*RedisRegistry) GetServices

func (r *RedisRegistry) GetServices() []*BackendService

GetServices returns a copy of the current list of backend services

func (RedisRegistry) GetTrie added in v0.0.30

func (r RedisRegistry) GetTrie() *RoutingTrie

func (*RedisRegistry) RemoveService

func (r *RedisRegistry) RemoveService(name string) error

RemoveService removes a backend service from Redis

func (*RedisRegistry) UpdateService

func (r *RedisRegistry) UpdateService(service *BackendService) error

UpdateService updates an existing backend service in Redis

type Route added in v0.0.30

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

type RoutingTrie added in v0.0.30

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

func (*RoutingTrie) BuildRoutes added in v0.0.30

func (rt *RoutingTrie) BuildRoutes(services []*BackendService)

func (*RoutingTrie) FindBackendService added in v0.0.30

func (rt *RoutingTrie) FindBackendService(r *http.Request) *BackendService

type ServiceRegistry

type ServiceRegistry interface {
	AddService(service *BackendService) error
	UpdateService(service *BackendService) error
	RemoveService(name string) error
	GetServices() []*BackendService
	GetTrie() *RoutingTrie
}

ServiceRegistry holds the methods to interact with the backend service registry

func NewMongoServiceRegistry

func NewMongoServiceRegistry(ctx context.Context, client *mongo.Client, database string, collection string, br *baseRegistry) (ServiceRegistry, error)

func NewServiceRegistry

func NewServiceRegistry(ctx context.Context, serviceType string, config *config.Config) (ServiceRegistry, error)

type YAMLServiceRegistry

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

YAMLServiceRegistry implements the ServiceRegistry interface

func NewYAMLServiceRegistry

func NewYAMLServiceRegistry(filename string, br *baseRegistry) (*YAMLServiceRegistry, error)

NewYAMLServiceRegistry creates a new YAMLServiceRegistry instance from a file

func (*YAMLServiceRegistry) AddService

func (r *YAMLServiceRegistry) AddService(service *BackendService) error

AddService adds a new backend service to the registry

func (*YAMLServiceRegistry) GetServices

func (r *YAMLServiceRegistry) GetServices() []*BackendService

GetServices returns a copy of the current list of backend services

func (YAMLServiceRegistry) GetTrie added in v0.0.30

func (r YAMLServiceRegistry) GetTrie() *RoutingTrie

func (*YAMLServiceRegistry) RemoveService

func (r *YAMLServiceRegistry) RemoveService(name string) error

RemoveService removes a backend service from the registry

func (*YAMLServiceRegistry) UpdateService

func (r *YAMLServiceRegistry) UpdateService(service *BackendService) error

UpdateService updates an existing backend service in the registry

Jump to

Keyboard shortcuts

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