service

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ClosedState = iota
	OpenState
)

CircuitBreaker states.

Variables

View Source
var (
	// ErrCircuitOpen indicates that the circuit breaker is open.
	ErrCircuitOpen                        = errors.New("unable to connect to server at host")
	ErrUnexpectedCircuitBreakerResultType = errors.New("unexpected result type from circuit breaker")
)

Functions

This section is empty.

Types

type CircuitBreaker added in v0.2.0

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

CircuitBreaker represents a circuit breaker implementation.

func NewCircuitBreaker added in v0.2.0

func NewCircuitBreaker(config CircuitBreakerConfig, h HTTP) *CircuitBreaker

NewCircuitBreaker creates a new CircuitBreaker instance based on the provided config.

func (*CircuitBreaker) DeleteWithHeaders added in v0.2.0

func (cb *CircuitBreaker) DeleteWithHeaders(ctx context.Context, path string, body []byte, headers map[string]string) (
	*http.Response, error)

DeleteWithHeaders is a wrapper for doRequest with the DELETE method and headers.

func (*CircuitBreaker) GetWithHeaders added in v0.2.0

func (cb *CircuitBreaker) GetWithHeaders(ctx context.Context, path string, queryParams map[string]interface{},
	headers map[string]string) (*http.Response, error)

func (*CircuitBreaker) PatchWithHeaders added in v0.2.0

func (cb *CircuitBreaker) PatchWithHeaders(ctx context.Context, path string, queryParams map[string]interface{},
	body []byte, headers map[string]string) (*http.Response, error)

PatchWithHeaders is a wrapper for doRequest with the PATCH method and headers.

func (*CircuitBreaker) PostWithHeaders added in v0.2.0

func (cb *CircuitBreaker) PostWithHeaders(ctx context.Context, path string, queryParams map[string]interface{},
	body []byte, headers map[string]string) (*http.Response, error)

PostWithHeaders is a wrapper for doRequest with the POST method and headers.

func (*CircuitBreaker) PutWithHeaders added in v0.2.0

func (cb *CircuitBreaker) PutWithHeaders(ctx context.Context, path string, queryParams map[string]interface{},
	body []byte, headers map[string]string) (*http.Response, error)

PutWithHeaders is a wrapper for doRequest with the PUT method and headers.

type CircuitBreakerConfig added in v0.2.0

type CircuitBreakerConfig struct {
	Threshold int           // Threshold represents the max no of retry before switching the circuit breaker state.
	Interval  time.Duration // Interval represents the time interval duration between hitting the HealthURL
}

CircuitBreakerConfig holds the configuration for the CircuitBreaker.

type ErrorLog

type ErrorLog struct {
	Log
	ErrorMessage string `json:"errorMessage"`
}

type HTTP

type HTTP interface {

	// HealthCheck to get the service health and report it to the current application
	HealthCheck(ctx context.Context) *Health
	// contains filtered or unexported methods
}

func NewHTTPService

func NewHTTPService(serviceAddress string, logger Logger, metrics Metrics, options ...Options) HTTP

NewHTTPService function creates a new instance of the httpService struct, which implements the HTTP interface. It initializes the http.Client, url, Tracer, and Logger fields of the httpService struct with the provided values.

type Health added in v0.2.0

type Health struct {
	Status  string                 `json:"status"`
	Details map[string]interface{} `json:"details"`
}

type HealthConfig added in v0.2.0

type HealthConfig struct {
	HealthEndpoint string
}

type Log

type Log struct {
	Timestamp     time.Time `json:"timestamp"`
	ResponseTime  int64     `json:"latency"`
	CorrelationID string    `json:"correlationId"`
	ResponseCode  int       `json:"responseCode"`
	HTTPMethod    string    `json:"httpMethod"`
	URI           string    `json:"uri"`
}

type Logger

type Logger interface {
	Log(args ...interface{})
}

type Metrics added in v0.3.0

type Metrics interface {
	IncrementCounter(ctx context.Context, name string, labels ...string)
	DeltaUpDownCounter(ctx context.Context, name string, value float64, labels ...string)
	RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
	SetGauge(name string, value float64)
}

type Options added in v0.2.0

type Options interface {
	// contains filtered or unexported methods
}

type Response

type Response struct {
	Body       []byte
	StatusCode int
	// contains filtered or unexported fields
}

func (*Response) GetHeader

func (r *Response) GetHeader(key string) string

Jump to

Keyboard shortcuts

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