util

package
v0.0.0-...-f47fe49 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRequestEmpty = NewErrBadRequest("")
View Source
var ErrNotFoundEmpty = NewErrNotFound("")
View Source
var FilterRegex = regexp.MustCompile(`\w+`)

Simple regex - which matches only the characters. the filters would come in like this:

filter[name][eq] or filter[source_type][name][eq]

and get matched as:

["filter", "name", "eq"] or ["filter", "source_type", "name", "eq"]

View Source
var RecordDateTimeFormat = "2006-01-02 15:04:05 MST"

Functions

func Capitalize

func Capitalize(str string) string

func DateTimePointerToRFC3339

func DateTimePointerToRFC3339(inputTime *time.Time) string

func DateTimePointerToRecordFormat

func DateTimePointerToRecordFormat(inputTime *time.Time) *string

func DateTimeToRFC3339

func DateTimeToRFC3339(inputTime time.Time) string

func DateTimeToRecordFormat

func DateTimeToRecordFormat(inputTime time.Time) *string

func Decrypt

func Decrypt(str string) (string, error)

Decrypts a password into a string

func ElementsInSlicesEqual

func ElementsInSlicesEqual(sliceA []int64, sliceB []int64) bool

ElementsInSlicesEqual sorts and compare slices of int64 and returns that slices are equal

func Encrypt

func Encrypt(str string) (string, error)

Encrypts str into a password_hash using the encryption key in the environment

func FormatAvailabilityStatus

func FormatAvailabilityStatus(status string) string

func FormatTimeToString

func FormatTimeToString(inputTime time.Time, format string) string

func GeneratedXRhIdentity

func GeneratedXRhIdentity(account, orgId string) string

GeneratedXRhIdentity returns a base64 encoded header to use as x-rh-identity when one is not provided

func IdentityFromKafkaHeaders

func IdentityFromKafkaHeaders(headers []kafka.Header) (*identity.Identity, error)

IdentityFromKafkaHeaders returns an identity from the provided Kafka headers, if the array contains one of the "x-rh-sources-account-number" or "x-rh-identity" headers. It returns early on the first match, without any specific preference or order.

func InitializeEncryption

func InitializeEncryption()

InitializeEncryption allows reinitializing the encryption key by reading from the "ENCRYPTION_KEY" environment variable again. Useful for testing purposes outside the "util" package.

func InterfaceToInt64

func InterfaceToInt64(i interface{}) (int64, error)

InterfaceToInt64 takes an interface and returns an int64 for any float64, int64 or string received -whether they are pointers or not-.

func InterfaceToString

func InterfaceToString(i interface{}) (string, error)

InterfaceToString takes a number in interface format and converts it to the string representation

func NewErrBadRequest

func NewErrBadRequest(t interface{}) error

func NewErrNotFound

func NewErrNotFound(t string) error

func OverrideEncryptionKey

func OverrideEncryptionKey(k string)

func ParseXRHIDHeader

func ParseXRHIDHeader(inputIdentity string) (*identity.XRHID, error)

func SliceContainsString

func SliceContainsString(slice []string, target string) bool

SliceContainsString returns true if the specified target is present in the given slice.

func StringRef

func StringRef(str string) *string

func StringValueOrNil

func StringValueOrNil(inputValue interface{}) *string

func ValueOrBlank

func ValueOrBlank(strRef *string) string

Types

type Collection

type Collection struct {
	Data  []interface{} `json:"data"`
	Meta  Metadata      `json:"meta"`
	Links Links         `json:"links"`
}

func CollectionResponse

func CollectionResponse(collection []interface{}, req *http.Request, count, limit, offset int) *Collection

type ErrBadRequest

type ErrBadRequest struct {
	Message string
}

func (ErrBadRequest) Error

func (e ErrBadRequest) Error() string

func (ErrBadRequest) Is

func (e ErrBadRequest) Is(err error) bool

type ErrNotFound

type ErrNotFound struct {
	Type string
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

func (ErrNotFound) Is

func (e ErrNotFound) Is(err error) bool

type Error

type Error struct {
	Detail    string `json:"detail"`
	Status    string `json:"status"`
	RequestId string `json:"request_id,omitempty"`
}

type ErrorDocument

type ErrorDocument struct {
	Errors []Error `json:"errors"`
}

func ErrorDoc

func ErrorDoc(message, status string) *ErrorDocument

func ErrorDocWithRequestId

func ErrorDocWithRequestId(message, status, uuid string) *ErrorDocument

func ErrorDocWithoutLogging

func ErrorDocWithoutLogging(message, status string) *ErrorDocument

type Filter

type Filter struct {
	Subresource string
	Name        string
	Operation   string
	Value       []string
}
type Links struct {
	First string `json:"first"`
	Last  string `json:"last"`
}

type Metadata

type Metadata struct {
	Count  int `json:"count"`
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

type Resource

type Resource struct {
	ResourceType  string
	ResourceID    int64
	ResourceUID   string
	TenantID      int64
	AccountNumber string
}

func ParseStatusMessageToResource

func ParseStatusMessageToResource(resource *Resource, statusMessage types.StatusMessage) (*Resource, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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