util

package
v1.4.32 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 25 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SystemContext = WithSystemContext(context.TODO())

Functions

func ArrToChan

func ArrToChan[T interface{}](arr []T) chan T

func ArrayContains added in v1.1.37

func ArrayContains[T comparable](arr []T, elem T) bool

func ArrayDiffer

func ArrayDiffer[T interface{}](existing []T, updated []T, hasSameId func(a, b T) bool, isEqual func(a, b T) bool, onNew func(rec T) error, onUpdate func(e, u T) error, onDelete func(rec T) error) error

func ArrayFilter added in v1.1.37

func ArrayFilter[T interface{}](arr []T, predicate func(elem T) bool) []T

func ArrayFirst

func ArrayFirst[T interface{}](arr []*T) *T

func ArrayMap

func ArrayMap[T interface{}, R interface{}](arr []T, mapper func(T) R) []R

func ArrayMapString

func ArrayMapString(arr []string, mapper func(string) string) []string

func ArrayMapToId

func ArrayMapToId[T HasId](arr []T) []string

func ArrayMapToInterface

func ArrayMapToInterface[T interface{}](arr []T) []interface{}

func ArrayMapToString

func ArrayMapToString[T interface{}](arr []T, fn func(t T) string) []string

func ArrayMapWithError

func ArrayMapWithError[T interface{}, R interface{}](arr []T, mapper func(T) (R, error)) ([]R, error)

func ArrayMapX added in v1.1.48

func ArrayMapX[T interface{}, R interface{}](arr []*T, mapper func(*T) *R) []*R

func ArrayPrepend

func ArrayPrepend[T interface{}](arr []*T, elem *T) []*T

func ArrayToMap added in v1.1.37

func ArrayToMap[T interface{}, R interface{}, K comparable](arr []T, keyFunc func(T) K, valueFunc func(T) R) map[K]R

func ArrayUnique added in v1.1.37

func ArrayUnique[T comparable](slice []T) []T

func Capitalize added in v1.1.37

func Capitalize(str string) string

func Coalesce

func Coalesce[T interface{}](val ...*T) *T

func CoalesceThen

func CoalesceThen[T interface{}](fn func(val *T) error, val ...*T) error

func DeCapitalize added in v1.2.21

func DeCapitalize(str string) string

func DePointer added in v1.1.48

func DePointer[T interface{}](val *T, defaultValue T) T

func EncodeKey added in v1.1.37

func EncodeKey(key string) (string, error)

func FlatMap added in v1.1.37

func FlatMap[T interface{}](arr ...[]T) []T

func FromAny

func FromAny[T proto.Message](anyItem *anypb.Any, instance T) T

func GetArrayIndex

func GetArrayIndex[T comparable](items []T, item T, comparator func(a, b T) bool) int

func GetErrorCode

func GetErrorCode(err error) model.ErrorCode

func GetErrorFields

func GetErrorFields(err error) []*model.ErrorField

func GetErrorMessage

func GetErrorMessage(err error) string

func GetNamedMap

func GetNamedMap[T Named](items []T) map[string]T

func GetRecordId added in v1.2.36

func GetRecordId(record *model.Record) string

func GetResourceSinglePrimaryProp

func GetResourceSinglePrimaryProp(resource *model.Resource) *model.ResourceProperty

func HasResourcePrimaryProp

func HasResourcePrimaryProp(resource *model.Resource) bool

func HasResourceSinglePrimaryProp

func HasResourceSinglePrimaryProp(resource *model.Resource) bool

func HistoryResource

func HistoryResource(resource *model.Resource) *model.Resource

func IdRecord added in v1.2.36

func IdRecord(id string) *model.Record

func IsFilterableProperty added in v1.3.76

func IsFilterableProperty(propertyType model.ResourceProperty_Type) bool

func IsSameIdentifiedResourceIndex

func IsSameIdentifiedResourceIndex(index1, index2 *model.ResourceIndex) bool

func IsSameIdentifiedResourceProperty

func IsSameIdentifiedResourceProperty(property1, property2 *model.ResourceProperty) bool

func IsSameRecord

func IsSameRecord(existing, updated *model.Record) bool

func IsSameResourceIndex

func IsSameResourceIndex(index1, index2 *model.ResourceIndex) bool

func IsSameResourceProperty

func IsSameResourceProperty(property1, property2 *model.ResourceProperty) bool

func IsSystemContext added in v1.1.37

func IsSystemContext(ctx context.Context) bool

func Keys added in v1.3.76

func Keys[T any](u map[string]T) []string

func LocateArrayElement added in v1.1.37

func LocateArrayElement[T interface{}](arr []*T, test func(elem *T) bool) *T

func LocatePropertyByName

func LocatePropertyByName(resource *model.Resource, propertyName string) *model.ResourceProperty

func MapStructValue

func MapStructValue(v map[string]interface{}) *structpb.Value

func NewContextWithValues added in v1.2.21

func NewContextWithValues(parent context.Context, valuesFrom context.Context) context.Context

func NormalizeResource

func NormalizeResource(resource *model.Resource)

func ParseType added in v1.3.15

func ParseType(elemType string) abs.ResourceIdentity

func PathSlug added in v1.2.82

func PathSlug(s string) string

func Pointer added in v1.1.37

func Pointer[T interface{}](val T) *T

func PrepareQuery

func PrepareQuery(resource *model.Resource, queryMap map[string]interface{}) (*model.BooleanExpression, error)

func PropertiesWithTitleToJsonSchema added in v1.1.37

func PropertiesWithTitleToJsonSchema(resource *model.Resource, elem PropertiesWithTitleAndDescription) *openapi3.Schema

func QueryAndExpression added in v1.1.37

func QueryAndExpression(left *model.BooleanExpression, right *model.BooleanExpression) *model.BooleanExpression

func QueryEqualExpression added in v1.1.37

func QueryEqualExpression(propertyName string, val *structpb.Value) *model.BooleanExpression

func QueryInExpression added in v1.1.37

func QueryInExpression(propertyName string, val *structpb.Value) *model.BooleanExpression

func QueryOrExpression added in v1.1.37

func QueryOrExpression(left *model.BooleanExpression, right *model.BooleanExpression) *model.BooleanExpression

func RandomHex

func RandomHex(n int) string

func Read

func Read(fileName string, msg proto.Message) error

func ReadJson

func ReadJson(fileName string, msg proto.Message) error

func RecordIdentifierPrimaryProperties

func RecordIdentifierPrimaryProperties(resource *model.Resource, properties map[string]*structpb.Value) (map[string]*structpb.Value, bool)

func RecordIdentifierProperties

func RecordIdentifierProperties(resource *model.Resource, properties map[string]*structpb.Value) (map[string]*structpb.Value, error)

func RecordIdentifierQuery added in v1.1.37

func RecordIdentifierQuery(resource *model.Resource, properties map[string]*structpb.Value) (*model.BooleanExpression, error)

func RecordIdentifierUniqueProperties

func RecordIdentifierUniqueProperties(resource *model.Resource, properties map[string]*structpb.Value) (map[string]*structpb.Value, bool)

func RecordMatchIdentifiableProperties added in v1.1.37

func RecordMatchIdentifiableProperties(resource *model.Resource, record *model.Record, properties map[string]*structpb.Value) (bool, error)

func RecordPropertyAccessorByPath added in v1.1.37

func RecordPropertyAccessorByPath(properties map[string]*structpb.Value, path string) (getter func() *structpb.Value, setter func(val *structpb.Value))

func RemarkResource

func RemarkResource(resource *model.Resource)

func ResourceJsonSchemaName added in v1.1.37

func ResourceJsonSchemaName(item *model.Resource) string

func ResourcePropertyPaths added in v1.3.95

func ResourcePropertyPaths(resource *model.Resource) map[string]bool

func ResourcePropertyTypeToJsonSchemaType

func ResourcePropertyTypeToJsonSchemaType(resource *model.Resource, property *model.ResourceProperty) *openapi3.SchemaRef

func ResourceRestPath added in v1.2.36

func ResourceRestPath(resource *model.Resource) string

func ResourceToJsonSchema added in v1.1.37

func ResourceToJsonSchema(resource *model.Resource) *openapi3.Schema

func ResourceWalkProperties added in v1.1.37

func ResourceWalkProperties(resource *model.Resource, callback func(path string, property *model.ResourceProperty))

func SnakeCaseToCamelCase

func SnakeCaseToCamelCase(inputUnderScoreStr string) (camelCase string)

func StripSpaces added in v1.1.37

func StripSpaces(str string) string

func StructKv

func StructKv(key string, value interface{}) *structpb.Value

func StructKv2

func StructKv2(key1 string, value1 interface{}, key2 string, value2 interface{}) *structpb.Value

func ToAny

func ToAny(instance proto.Message) *anypb.Any

func ToDashCase

func ToDashCase(str string) string

func ToSnakeCase

func ToSnakeCase(str string) string

func ToStatusError

func ToStatusError(err error) error

func VerifyKey added in v1.1.37

func VerifyKey(hash, key string) error

func WithSystemContext added in v1.1.37

func WithSystemContext(ctx context.Context) context.Context

func Write

func Write(fileName string, msg proto.Message) error

func WriteJson

func WriteJson(fileName string, msg proto.Message) error

Types

type HasId

type HasId interface {
	GetId() string
}

type MapEntry added in v1.2.57

type MapEntry[T interface{}] struct {
	Key string
	Val T
}

func MapToArray added in v1.2.57

func MapToArray[T interface{}](arr map[string]T) []MapEntry[T]

type Named

type Named interface {
	GetName() string
}

type PropertiesWithTitleAndDescription added in v1.1.37

type PropertiesWithTitleAndDescription interface {
	GetTitle() string
	GetDescription() string
	GetProperties() []*model.ResourceProperty
}

type PropertyAccessor

type PropertyAccessor struct {
	Property *model.ResourceProperty
	Get      func(record *model.Record) interface{}
	Set      func(record *model.Record, val interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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