helpers

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CouldNotUnmarshalResponseBytes = "Could not unmarshal reponseBytes. %v"

CouldNotUnmarshalResponseBytes is a string constant saying could not unmarshal responseBytes.

View Source
const ErrorWasNotNil = "Error was not nil, %v"

ErrorWasNotNil is a string constant for unit testing.

View Source
const FailureMarshaling = "Failure Marshalling: %v"

FailureMarshaling is a string constant saying Failure Marshalling.

View Source
const NilError = "error is nil"

NilError is a string constant for unit testing.

View Source
const NilID = "nil id"

NilID is a string constant saying nil id.

View Source
const ResponseWasNotAsExpected = "Response was not as expected"

ResponseWasNotAsExpected is a string constant for unit testing.

View Source
const WrongErrorText = "Wrong error text: %s"

WrongErrorText is a string constant for unit testing.

Variables

View Source
var (
	// Client is an implementation of HTTP Client for making calls with Do.
	Client HTTPClient
	// CachingClientVar is an implementation of the caching interface for whichever caching implementation is used.
	CachingClientVar CachingClient
)

Functions

func EsiTTLToMillis added in v0.0.2

func EsiTTLToMillis(ctx context.Context, esiTime string) int64

EsiTTLToMillis takes in a context for tracing purposes and a RFC1123 time for conversion to millis for TTL. This is done by taking the current time and subtracting the inbound time to get the millis until the TTL should occur.

func SetupRestHelper

func SetupRestHelper()

SetupRestHelper sets up required dependency injection

Types

type CachingClient

type CachingClient interface {
	AddToCache(ctx context.Context, key string, value []byte, ttl int64)
	CheckCache(ctx context.Context, key string) (bool, []byte)
}

CachingClient is an interface for the caching package for mocking during Unit Tests

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface for the http Do method for mocking during Unit Tests.

type RestHelperClient

type RestHelperClient struct {
}

RestHelperClient is the client making cached REST calls.

func (*RestHelperClient) MakeCachingRESTCall

func (r *RestHelperClient) MakeCachingRESTCall(ctx context.Context, baseURL string, verb string, body bytes.Buffer, additionalQueryParams []configuration.KeyValue, redisQueryKey string) ([]byte, http.Header, error)

MakeCachingRESTCall takes in a context for tracing, the baseURL is the url minus query parameters, verb is the http verb in string form, body is a byte buffer of a JSON body to be sent, additionalQueryParams are the query params beyond the default ones to be sent, redisQueryKey is the unique query key by which the response will be saved and retrieved from the cache.

Jump to

Keyboard shortcuts

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