util

package
v0.0.0-...-acaaaf6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TimeISO8601 = "2006-01-02"

Variables

View Source
var (
	ContextKeyRequestID = contextKey("RequestID")
)

Functions

func Check

func Check(err error, msg string)

Check the error and exit the process when not nil

func CheckFeedError

func CheckFeedError(logger *zap.SugaredLogger, err error, msg string)

CheckFeedError - checks the Feed for errors, except for 403's

func DeduplicateList

func DeduplicateList[T any](pkFun func(element *T) string, elements []*T) []*T

DeduplicateList a list of T type and maintains the latest value

func GenericCollectionMapper

func GenericCollectionMapper[T, R any](itemsSource []T, transformFn func(T) R) []R

GenericCollectionMapper will map from []T to []R by providing a transformation function

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext returns the Request ID stored in context or a new RequestID.

func SplitSliceInBatch

func SplitSliceInBatch[T any](size int, collection []T, fn func(batch []T) error) error

SplitSliceInBatch splits a slice into batches and calls the callback function for each batch.

func TimeFromString

func TimeFromString(input string) (time.Time, error)

TimeFromString will try to match the input to known formats

Types

type DefaultHTTPDoer

type DefaultHTTPDoer struct {
	Req        *http.Request
	HttpClient *http.Client
}

func (*DefaultHTTPDoer) Do

func (b *DefaultHTTPDoer) Do() (*http.Response, error)

func (*DefaultHTTPDoer) Error

func (b *DefaultHTTPDoer) Error() interface{}

func (*DefaultHTTPDoer) URL

func (b *DefaultHTTPDoer) URL() string

type HTTPError

type HTTPError struct {
	StatusCode int    `json:"status_code"`
	Resource   string `json:"resource"`
	Message    string `json:"message"`
}

HTTPError represents an easy way to pass HttpErrors from Sling

func (HTTPError) Error

func (h HTTPError) Error() string

type SlingHTTPDoer

type SlingHTTPDoer struct {
	Sl       *sling.Sling
	Req      *http.Request
	SuccessV interface{}
	FailureV interface{}
}

func (*SlingHTTPDoer) Do

func (b *SlingHTTPDoer) Do() (*http.Response, error)

func (*SlingHTTPDoer) Error

func (b *SlingHTTPDoer) Error() interface{}

func (*SlingHTTPDoer) URL

func (b *SlingHTTPDoer) URL() string

Jump to

Keyboard shortcuts

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