helpers

package
v0.0.0-...-ebc7474 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetryAttempts      = 5
	DefaultRequestTimeout = 3*time.Second + 50*time.Millisecond // Close to 3.05
	DefaultServiceURL     = "https://example.com/api"           // Replace with actual URL
)
View Source
const DATETIME_FORMAT = "2006-01-02T15:04:05.000Z"

Variables

View Source
var REQUIRED_OUTPUTS = map[string]map[string]string{
	"aws-firehose": {
		"alerts": "{prefix}_streamalert_alert_delivery",
	},
}

Functions

func Difference

func Difference(a, b []string) []string

difference returns the difference of two slices (a - b)

func EqualStringSlices

func EqualStringSlices(a, b []string) bool

EqualStringSlices checks if two string slices are equal

func GetFirstKey

func GetFirstKey(data any, searchKey string, defaultValue any) any

func GetKeys

func GetKeys(data any, searchKey string, maxMatches int) []any

GetKeys searches for a key anywhere in the nested data structure, returning all associated values.

func GetRequiredOutputs

func GetRequiredOutputs() []string

GetRequiredOutputs iterates through the required outputs and collapses to the right format

func Intersect

func Intersect(a, b []string) []string

intersect returns the intersection of two slices

func JsonCompact

func JsonCompact(v any) string

func LoadPlugins

func LoadPlugins[T any](paths []string) ([]T, error)

func MergeRequiredOutputs

func MergeRequiredOutputs(userConfig map[string]map[string]string, prefix string) map[string]map[string]string

MergeRequiredOutputs iterates through the required outputs and merges them with the user outputs

Types

type OutputRequestFailure

type OutputRequestFailure struct {
	Response *http.Response
}

func (*OutputRequestFailure) Error

func (e *OutputRequestFailure) Error() string

type RequestHelper

type RequestHelper struct{}

func (*RequestHelper) CatchExceptions

func (h *RequestHelper) CatchExceptions() []any

func (*RequestHelper) CheckHTTPResponse

func (h *RequestHelper) CheckHTTPResponse(response *http.Response) bool

func (*RequestHelper) GetRequest

func (h *RequestHelper) GetRequest(url string, headers map[string]string) (*http.Response, error)

func (*RequestHelper) GetRequestRetry

func (h *RequestHelper) GetRequestRetry(url string, headers map[string]string, exceptions []any) (*http.Response, error)

func (*RequestHelper) PostRequest

func (h *RequestHelper) PostRequest(url string, headers map[string]string, data any) (*http.Response, error)

func (*RequestHelper) PostRequestRetry

func (h *RequestHelper) PostRequestRetry(url string, headers map[string]string, data any, exceptions []any) (*http.Response, error)

func (*RequestHelper) PutRequest

func (h *RequestHelper) PutRequest(url string, headers map[string]string, data any) (*http.Response, error)

func (*RequestHelper) PutRequestRetry

func (h *RequestHelper) PutRequestRetry(url string, headers map[string]string, data any, exceptions []any) (*http.Response, error)

func (*RequestHelper) RetryOnException

func (h *RequestHelper) RetryOnException(fn func() (*http.Response, error), exceptions []any) (*http.Response, error)

Jump to

Keyboard shortcuts

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