util

package
v1.1.45 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 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) errors.ServiceError, onUpdate func(e, u T) errors.ServiceError, onDelete func(rec T) errors.ServiceError) errors.ServiceError

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, errors.ServiceError)) ([]R, errors.ServiceError)

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) errors.ServiceError, val ...*T) errors.ServiceError

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 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 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 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 NormalizeResource

func NormalizeResource(resource *model.Resource)

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, errors.ServiceError)

func PrepareQueryFromFilters

func PrepareQueryFromFilters(resource *model.Resource, filters map[string]string) (*model.BooleanExpression, errors.ServiceError)

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 ResourcePropertyTypeToJsonSchemaType

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

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 errors.ServiceError) 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 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