Documentation ¶
Overview ¶
Package service provides an HTTP client with features for logging, metrics, and resilience.It supports various functionalities like health checks, circuit-breaker and various authentication.
Package service is a generated GoMock package.
Index ¶
- Constants
- Variables
- func NewCircuitBreaker(config CircuitBreakerConfig, h HTTP) *circuitBreaker
- type APIKeyConfig
- type BasicAuthConfig
- type CircuitBreakerConfig
- type DefaultHeaders
- type ErrorLog
- type HTTP
- type Health
- type HealthConfig
- type Log
- type Logger
- type Metrics
- type MockMetrics
- type MockMetricsMockRecorder
- type OAuthConfig
- type Options
- type Response
Constants ¶
const ( ClosedState = iota OpenState )
circuitBreaker states.
Variables ¶
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 ¶
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.
Types ¶
type APIKeyConfig ¶ added in v1.1.1
type APIKeyConfig struct {
APIKey string
}
func (*APIKeyConfig) AddOption ¶ added in v1.2.0
func (a *APIKeyConfig) AddOption(h HTTP) HTTP
type BasicAuthConfig ¶ added in v1.1.1
func (*BasicAuthConfig) AddOption ¶ added in v1.2.0
func (a *BasicAuthConfig) AddOption(h HTTP) HTTP
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.
func (*CircuitBreakerConfig) AddOption ¶ added in v1.2.0
func (cb *CircuitBreakerConfig) AddOption(h HTTP) HTTP
type DefaultHeaders ¶ added in v1.7.0
func (*DefaultHeaders) AddOption ¶ added in v1.7.0
func (a *DefaultHeaders) AddOption(h HTTP) HTTP
type ErrorLog ¶
func (*ErrorLog) PrettyPrint ¶ added in v1.4.0
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 ¶
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 HealthConfig ¶ added in v0.2.0
type HealthConfig struct {
HealthEndpoint string
}
func (*HealthConfig) AddOption ¶ added in v1.2.0
func (h *HealthConfig) AddOption(svc HTTP) HTTP
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"` }
func (*Log) PrettyPrint ¶ added in v1.4.0
type MockMetrics ¶ added in v1.1.1
type MockMetrics struct {
// contains filtered or unexported fields
}
MockMetrics is a mock of Metrics interface.
func NewMockMetrics ¶ added in v1.1.1
func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics
NewMockMetrics creates a new mock instance.
func (*MockMetrics) EXPECT ¶ added in v1.1.1
func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockMetrics) RecordHistogram ¶ added in v1.1.1
func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
RecordHistogram mocks base method.
type MockMetricsMockRecorder ¶ added in v1.1.1
type MockMetricsMockRecorder struct {
// contains filtered or unexported fields
}
MockMetricsMockRecorder is the mock recorder for MockMetrics.
func (*MockMetricsMockRecorder) RecordHistogram ¶ added in v1.1.1
func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call
RecordHistogram indicates an expected call of RecordHistogram.
type OAuthConfig ¶ added in v1.1.1
type OAuthConfig struct { // ClientID is the application's ID. ClientID string // ClientSecret is the application's secret. ClientSecret string // TokenURL is the resource server's token endpoint // URL. This is a constant specific to each server. TokenURL string // Scope specifies optional requested permissions. Scopes []string // EndpointParams specifies additional parameters for requests to the token endpoint. EndpointParams url.Values }
OAuthConfig describes a 2-legged OAuth2 flow, with both the client application information and the server's endpoint URLs.
func (*OAuthConfig) AddOption ¶ added in v1.2.0
func (h *OAuthConfig) AddOption(svc HTTP) HTTP