service

package
v0.0.0-...-96059aa Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

package service provides functions and methods for creating and running the api of the proxy service

Index

Constants

View Source
const (
	DefaultAnonymousUserAgent = "anon"
	// Service defined context keys
	DecodedRequestContextKey              = "X-FURY-PROXY-DECODED-REQUEST-BODY"
	OriginRoundtripLatencyMillisecondsKey = "X-FURY-PROXY-ORIGIN-ROUNDTRIP-LATENCY-MILLISECONDS"
	RequestStartTimeContextKey            = "X-FURY-PROXY-REQUEST-START-TIME"
	RequestHostnameContextKey             = "X-FURY-PROXY-REQUEST-HOSTNAME"
	RequestIPContextKey                   = "X-FURY-PROXY-REQUEST-IP"
	RequestUserAgentContextKey            = "X-FURY-PROXY-USER-AGENT"
	RequestRefererContextKey              = "X-FURY-PROXY-REFERER"
	RequestOriginContextKey               = "X-FURY-PROXY-ORIGIN"
	// Values defined by upstream services
	LoadBalancerForwardedForHeaderKey = "X-Forwarded-For"
	UserAgentHeaderkey                = "User-Agent"
	RefererHeaderKey                  = "Referer"
	OriginHeaderKey                   = "Origin"
)
View Source
const (
	DatabaseStatusPath = "/status/database"
)

Variables

This section is empty.

Functions

func Call

func Call(client ProxyServiceClient, request *http.Request, result interface{}) error

Call makes an http request to a JSON HTTP api decoding the JSON response to the result interface if non-nil returning error (if any)

func CreateRequest

func CreateRequest(method string, path string, params interface{}) (*http.Request, error)

CreateRequest isolates duplicate code in creating http search request.

func MarshalJSONResponse

func MarshalJSONResponse(obj interface{}, w http.ResponseWriter) error

MarshalJSONResponse marshals an interface into the response body and sets JSON content type headers

func NewError

func NewError(message, url string, statusCode int) error

NewError creates a new RequestError

Types

type DatabaseStatusResponse

type DatabaseStatusResponse struct {
	LatestProxiedRequestMetricPartitionTableName string `json:"latest_proxied_request_metric_partition_table_name"` // name of the latest created and currently attached partition for the proxied_request_metrics table
	TotalProxiedRequestMetricPartitions          int64  `json:"total_proxied_request_metric_partitions"`            // total number of attached partitions for the proxied_request_metrics table
}

DatabaseStatusResponse wraps values returned by calls to /status/database

type ProxyService

type ProxyService struct {
	Database *database.PostgresClient

	*logging.ServiceLogger
	// contains filtered or unexported fields
}

ProxyService represents an instance of the proxy service API

func New

func New(ctx context.Context, config config.Config, serviceLogger *logging.ServiceLogger) (ProxyService, error)

New returns a new ProxyService with the specified config and error (if any)

func (*ProxyService) Run

func (p *ProxyService) Run() error

Run runs the proxy service, returning error (if any) in the event the proxy service stops

type ProxyServiceClient

type ProxyServiceClient struct {
	*http.Client

	DebugLogResponses bool
	// contains filtered or unexported fields
}

ProxyServiceClient provides a client for making requests and decoding responses to the proxy service API

func NewProxyServiceClient

func NewProxyServiceClient(config ProxyServiceClientConfig) (*ProxyServiceClient, error)

NewProxyServiceClient creates a new ProxyServiceClient using the provided config, returning the client and error (if any)

func (*ProxyServiceClient) GetDatabaseStatus

func (c *ProxyServiceClient) GetDatabaseStatus(ctx context.Context) (DatabaseStatusResponse, error)

GetDatabaseStatus calls `DatabaseStatusPath` to get metadata related to proxy service database operations such as proxied request metrics compaction and partitioning

type ProxyServiceClientConfig

type ProxyServiceClientConfig struct {
	ProxyServiceHostname string
	DebugLogResponses    bool
}

ProxyServiceClientConfig wraps values used to create a new ProxyServiceClient

type RequestError

type RequestError struct {
	URL        string
	StatusCode int
	// contains filtered or unexported fields
}

RequestError provides additional details about the failed request.

func (*RequestError) Error

func (err *RequestError) Error() string

Error implements the error interface for RequestError.

type RequestInterceptor

type RequestInterceptor func([]byte) ([]byte, error)

RequestInterceptors (a.k.a. 🦖🦖) are functions run by the proxy service to modify the original request sent by the caller or the response returned by the backend

Jump to

Keyboard shortcuts

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