client

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCircuitBreakerFailure

func IsCircuitBreakerFailure(statusCode int, err error) bool

func IsRetryableError added in v1.1.1

func IsRetryableError(statusCode int, err error) bool

Обновленная версия IsRetryableError

func IsSuccessfulResponse

func IsSuccessfulResponse(statusCode int, err error) bool

func NewManager

func NewManager(ctx context.Context, config types.ConfigManager, logger types.Logger, metrics types.MetricsManager, health types.HealthManager, middlewareManager types.MiddlewareManager, authProvider types.AuthProviderManager) (types.ClientManager, error)

Types

type CircuitBreaker

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

func NewCircuitBreaker

func NewCircuitBreaker(config *CircuitBreakerConfig, logger types.Logger, serviceName string) *CircuitBreaker

func (*CircuitBreaker) CanExecute

func (cb *CircuitBreaker) CanExecute() bool

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() (state int32, failures int32, lastFail int64)

func (*CircuitBreaker) GetStateString

func (cb *CircuitBreaker) GetStateString() string

func (*CircuitBreaker) IsRunning

func (cb *CircuitBreaker) IsRunning() bool

func (*CircuitBreaker) RecordFailure

func (cb *CircuitBreaker) RecordFailure()

func (*CircuitBreaker) RecordSuccess

func (cb *CircuitBreaker) RecordSuccess()

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

func (*CircuitBreaker) Stop

func (cb *CircuitBreaker) Stop() error

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	Enabled          bool          `yaml:"enabled" json:"enabled"`
	FailureThreshold int           `yaml:"failure_threshold" json:"failure_threshold"`
	RecoveryTimeout  time.Duration `yaml:"recovery_timeout" json:"recovery_timeout"`
	HalfOpenRequests int           `yaml:"half_open_requests" json:"half_open_requests"`
}

type CircuitBreakerState

type CircuitBreakerState int32
const (
	StateBreakerClosed CircuitBreakerState = iota
	StateBreakerOpen
	StateBreakerHalfOpen
	StateBreakerStopped
)

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(ctx context.Context, logger types.Logger, serviceName string, config *ServiceClientConfig) *HTTPClient

func (*HTTPClient) Call

func (c *HTTPClient) Call(method, path string, data interface{}, opts *types.CallOptions) ([]byte, int, error)

func (*HTTPClient) Close

func (c *HTTPClient) Close()

func (*HTTPClient) IsRunning

func (c *HTTPClient) IsRunning() bool

type HTTPClientConfig

type HTTPClientConfig struct {
	DefaultTimeout     time.Duration         `yaml:"default_timeout" json:"default_timeout"`
	MaxIdleConnections int                   `yaml:"max_idle_connections" json:"max_idle_connections"`
	IdleConnTimeout    time.Duration         `yaml:"idle_conn_timeout" json:"idle_conn_timeout"`
	DefaultRetries     int                   `yaml:"default_retries" json:"default_retries"`
	CircuitBreaker     *CircuitBreakerConfig `yaml:"circuit_breaker" json:"circuit_breaker"`
}

type Manager

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

func (*Manager) Call

func (m *Manager) Call(serviceName, method, path string, data interface{}, opts *types.CallOptions) ([]byte, int, error)

func (*Manager) IsRunning

func (m *Manager) IsRunning() bool

func (*Manager) RegisterWebhook

func (m *Manager) RegisterWebhook(serviceName, event, webhookURL string) ([]byte, int, error)

func (*Manager) Start

func (m *Manager) Start() error

func (*Manager) Stop

func (m *Manager) Stop() error

type ManagerState

type ManagerState int32
const (
	ManagerStateStopped ManagerState = iota
	ManagerStateStarting
	ManagerStateRunning
	ManagerStateStopping
)

type ServiceClientConfig

type ServiceClientConfig struct {
	BaseURL        string                `yaml:"base_url" json:"base_url"`
	Timeout        time.Duration         `yaml:"timeout" json:"timeout"`
	Retries        int                   `yaml:"retries" json:"retries"`
	CircuitBreaker *CircuitBreakerConfig `yaml:"circuit_breaker" json:"circuit_breaker"`
}

type State

type State int32
const (
	StateRunning State = iota
	StateStopping
	StateStopped
)

Jump to

Keyboard shortcuts

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