helpers

package
v0.0.0-...-82cc56b Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHeaders

func AddHeaders(req *http.Request, headers map[string]string)

AddHeaders adds headers to a request pre-flight

func ChanToSlice

func ChanToSlice[T any](channel *chan T) []T

ChanToSlice is a generic function that converts a buffered channel into a slice. This consumes the channel in the process.

func Clamp

func Clamp(v, min, max int64) int64

Clamp is a small helper that ensures that a given number v lies between bounds m, n. If it is outside of those bounds, it sets v to the closer of (m, n)

func Contains

func Contains[T any](slice []T, predicate func(T) bool) bool

Contains checks that a value exists within a slice. If not, returns false

func ContainsMatch

func ContainsMatch[T comparable](slice []T, value T) bool

ContainsMatch is an optimization on Contains that restricts checks to comparable elements.

func Filter

func Filter[T any](slice []T, predicate func(T) bool) []T

Filter is a generic function that searches through a list searching for all items that match the given predicate. This returns the elements that matched the predicate in the order they were encountered.

func Find

func Find[T any](slice []T, predicate func(T) bool) (int, *T)

Find is a generic function that searches through a list searching for an item that matches the given predicate. If found, returns the index where it was found, and a pointer to the actual data. If not found, return (-1, nil) Note: the search is sequential, but terminated once the element is found

func FindMatch

func FindMatch[T comparable](slice []T, value T) (int, *T)

FindMatch is a minor optimization of Find that restricts finds to only comparable elements.

func MakeJSONRequest

func MakeJSONRequest(method, url string, body io.Reader, updateRequest ModifyReqFunc) (*http.Response, error)

MakeJSONRequest makes a request with the content-type application/json, and an optional body

func Map

func Map[T any, U any](slice []T, mapFn func(T) U) []U

Map is a generic function that converts a list of type T into a list of type U, along with a function that converts a T to a U. This is essentially the same as a `map` function in other languages, like javascript

func NoMod

func NoMod(req *http.Request) error

NoMod is a canned value that can be used for MakeJSONRequest's updateRequest parameter

func PFalse

func PFalse() *bool

PFalse returns a pointer to a false value

func PTrue

func PTrue() *bool

PTrue returns a pointer to a true value

func Ptr

func Ptr[T any](t T) *T

Ptr is a small helper to convert a real value into a pointer to that value. Most useful as a way to turn a literal into a pointer to that literal

func SprintfPtr

func SprintfPtr(s string, vals ...any) *string

SprintfPtr is a wrapper around Sprintf that returns the result as a string pointer

func StrToLowerCaseUnderscore

func StrToLowerCaseUnderscore(str string) string

func StrToUpperCaseUnderscore

func StrToUpperCaseUnderscore(str string) string

Types

type ModifyReqFunc

type ModifyReqFunc = func(req *http.Request) error

type TimelineFilters

type TimelineFilters struct {
	UUID             filter.Values
	Text             []string
	Metadata         []string
	Tags             filter.Values
	Type             filter.Values
	Operator         filter.Values
	DateRanges       filter.DateValues
	WithEvidenceUUID filter.Values
	Linked           *bool
	SortAsc          bool
}

TimelineFilters represents all of the parsed timeline configuraions

func ParseTimelineQuery

func ParseTimelineQuery(query string) (TimelineFilters, error)

ParseTimelineQuery parses a query a user may type into the search box on the timeline page into a TimelineFilters struct that the events/evidence services expect

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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