functions

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncErrors = registryInstance.DefineNs("errors", NewEntry(
	&Errors{},
	NewFunctionNamespace(reflect.TypeOf(&Errors{})),
))
View Source
var FuncJSON = registryInstance.DefineNs("json", NewEntry(
	NewJSON(nil),
	NewFunctionNamespace(reflect.TypeOf(NewJSON(nil))),
))
View Source
var FuncMaps = registryInstance.DefineNs("maps", NewEntry(
	&Maps{},
	NewFunctionNamespace(reflect.TypeOf(&Maps{})),
))
View Source
var FuncMath = registryInstance.DefineNs("math", NewEntry(
	&Math{},
	NewFunctionNamespace(reflect.TypeOf(&Math{})),
))
View Source
var FuncSlices = registryInstance.DefineNs("slices", NewEntry(
	&Slices{},
	NewFunctionNamespace(reflect.TypeOf(&Slices{})),
))
View Source
var FuncStrconv = registryInstance.DefineNs("strconv", NewEntry(
	&Strconv{},
	NewFunctionNamespace(reflect.TypeOf(&Strconv{})),
))
View Source
var FuncStrings = registryInstance.DefineNs("strings", NewEntry(
	&Strings{},
	NewFunctionNamespace(reflect.TypeOf(&Strings{})),
))
View Source
var FuncTime = registryInstance.DefineNs("time", NewEntry(
	&Time{},
	NewFunctionNamespace(reflect.TypeOf(&Time{})),
))
View Source
var FuncTypes = registryInstance.DefineNs("types", NewEntry(
	&Types{},
	NewFunctionNamespace(reflect.TypeOf(&Types{})),
))
View Source
var HasKeyFunc = &StaticKindFunc{
	kind: reflect.Map,
	handler: func(aMap, aKey interface{}) (bool, error) {
		return reflect.ValueOf(aMap).MapIndex(reflect.ValueOf(keys.Normalize(aKey))).IsValid(), nil
	},
	resultType: reflect.TypeOf(true),
}
View Source
var MapHasKey = registryInstance.DefineNs("HasKey", NewEntry(
	HasKeyFunc.handler,
	NewFunctionKind([]reflect.Kind{HasKeyFunc.kind}),
))
View Source
var (
	Now = time.Now
)
View Source
var SliceIndexBy = registryInstance.DefineNs("IndexBy", NewEntry(
	SliceIndexByFunc.Handler(),
	NewFunctionKind(SliceIndexByFunc.Kind()),
))
View Source
var SliceIndexByFunc = &indexSliceByFunc{}

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Metadata interface{}
	Handler  interface{}
}

func NewEntry

func NewEntry(handler interface{}, metadata interface{}) *Entry

type Errors

type Errors struct {
}

func (Errors) AssertBool

func (e Errors) AssertBool(value interface{}) (bool, error)

func (Errors) AssertFloat

func (e Errors) AssertFloat(value interface{}) (bool, error)

func (Errors) AssertInt

func (e Errors) AssertInt(value interface{}) (bool, error)

func (Errors) AssertString

func (e Errors) AssertString(value interface{}) (bool, error)

func (Errors) AssertWithMessage

func (e Errors) AssertWithMessage(isValid bool, message string) (bool, error)

func (Errors) DiscoverInterfaces

func (e Errors) DiscoverInterfaces(aFunc interface{}) (func(args ...interface{}) (interface{}, error), reflect.Type, bool)

func (Errors) Raise

func (e Errors) Raise(message string) (string, error)

func (Errors) RegisterError

func (e Errors) RegisterError(message string) (string, error)

type FieldNameChecker

type FieldNameChecker func(field reflect.StructField, fieldName string) bool
var FieldChecker FieldNameChecker = func(field reflect.StructField, fieldName string) bool {
	return false
}

type FunctionKindMetadata

type FunctionKindMetadata struct {
	// contains filtered or unexported fields
}

func NewFunctionKind

func NewFunctionKind(kinds []reflect.Kind) *FunctionKindMetadata

func (*FunctionKindMetadata) Kinds

func (f *FunctionKindMetadata) Kinds() []reflect.Kind

type FunctionNamespaceMetadata

type FunctionNamespaceMetadata struct {
	// contains filtered or unexported fields
}

func NewFunctionNamespace

func NewFunctionNamespace(rType reflect.Type) *FunctionNamespaceMetadata

func (*FunctionNamespaceMetadata) Type

type JSON

type JSON struct {
	// contains filtered or unexported fields
}

func NewJSON

func NewJSON(typeParser TypeParser) *JSON

func (*JSON) Marshal

func (n *JSON) Marshal(any interface{}) (string, error)

func (*JSON) MethodResultType

func (n *JSON) MethodResultType(methodName string, call *expr.Call) (reflect.Type, error)

func (*JSON) UnmarshalInto

func (n *JSON) UnmarshalInto(data interface{}, typeRepresentation string) (interface{}, error)

type Maps

type Maps struct{}

func (Maps) Get

func (m Maps) Get(aMap interface{}, key interface{}) (interface{}, error)

func (Maps) GetBool

func (m Maps) GetBool(aMap interface{}, key interface{}) (bool, error)

func (Maps) GetFloat

func (m Maps) GetFloat(aMap interface{}, key interface{}) (float64, error)

func (Maps) GetInt

func (m Maps) GetInt(aMap interface{}, key interface{}) (int, error)

func (Maps) GetString

func (m Maps) GetString(aMap interface{}, key interface{}) (string, error)

func (Maps) Has

func (m Maps) Has(aMap interface{}, key interface{}) (bool, error)

type Math

type Math struct{}

func (Math) Abs

func (m Math) Abs(f float64) float64

func (Math) Ceil

func (m Math) Ceil(f float64) float64

func (Math) DiscoverInterfaces

func (m Math) DiscoverInterfaces(aFunc interface{}) (func(args ...interface{}) (interface{}, error), reflect.Type, bool)

func (Math) Floor

func (m Math) Floor(f float64) float64

func (Math) Max

func (m Math) Max(x, y float64) float64

func (Math) Min

func (m Math) Min(x, y float64) float64

func (Math) Pow

func (m Math) Pow(x, y float64) float64

func (Math) Round

func (m Math) Round(f float64) float64

func (Math) Sqrt

func (m Math) Sqrt(f float64) float64

type Registry

type Registry struct {
	Entries map[string]*Entry
}

func CopyInstance

func CopyInstance() *Registry

func NewRegistry

func NewRegistry() *Registry

func (*Registry) DefineNs

func (r *Registry) DefineNs(ns string, def *Entry) string

func (*Registry) IsDefined

func (r *Registry) IsDefined(ns string) bool

type Slices

type Slices struct {
}

func (Slices) BoolAt

func (s Slices) BoolAt(slice interface{}, index int) (bool, error)

func (Slices) FloatAt

func (s Slices) FloatAt(slice interface{}, index int) (float64, error)

func (Slices) IntAt

func (s Slices) IntAt(slice interface{}, index int) (int, error)

func (Slices) Length

func (s Slices) Length(slice interface{}) int

func (Slices) ReverseFloats

func (s Slices) ReverseFloats(slice interface{}) ([]float64, error)

func (Slices) ReverseInts

func (s Slices) ReverseInts(slice interface{}) ([]int, error)

func (Slices) ReverseStrings

func (s Slices) ReverseStrings(slice interface{}) ([]string, error)

func (Slices) StringAt

func (s Slices) StringAt(slice interface{}, index int) (string, error)

type StaticKindFunc

type StaticKindFunc struct {
	// contains filtered or unexported fields
}

func (*StaticKindFunc) Handler

func (a *StaticKindFunc) Handler() interface{}

func (*StaticKindFunc) Kind

func (a *StaticKindFunc) Kind() []reflect.Kind

type Strconv

type Strconv struct{}

func (Strconv) AsFloat

func (s Strconv) AsFloat(value interface{}) (float64, error)

func (Strconv) Atoi

func (s Strconv) Atoi(val string) (int, error)

func (Strconv) Itoa

func (s Strconv) Itoa(i int) string

func (Strconv) ParseBool

func (s Strconv) ParseBool(val string) (bool, error)

func (Strconv) ParseFloat

func (s Strconv) ParseFloat(val string) (float64, error)

func (Strconv) ParseUint

func (s Strconv) ParseUint(val string) (uint64, error)

type Strings

type Strings struct {
}

func (Strings) Fields

func (s Strings) Fields(val string) []string

func (Strings) HasPrefix

func (s Strings) HasPrefix(val, suffix string) bool

func (Strings) HasSuffix

func (s Strings) HasSuffix(val, suffix string) bool

func (Strings) In

func (s Strings) In(set []string, candidate string) bool

func (Strings) Index

func (s Strings) Index(val, substr string) int

func (Strings) LastIndex

func (s Strings) LastIndex(val, substr string) int

func (Strings) Length

func (s Strings) Length(val string) int

func (Strings) ReplaceAll

func (s Strings) ReplaceAll(val, old, new string) string

func (Strings) Split

func (s Strings) Split(val, sep string) []string

func (Strings) ToLower

func (s Strings) ToLower(val string) string

func (Strings) ToUpper

func (s Strings) ToUpper(val string) string

func (Strings) Trim

func (s Strings) Trim(val, cutset string) string

func (Strings) TrimSpace

func (s Strings) TrimSpace(val string) string

type Time

type Time struct {
}

func (Time) DiscoverInterfaces

func (t Time) DiscoverInterfaces(aFunc interface{}) (func(args ...interface{}) (interface{}, error), reflect.Type, bool)

func (Time) Now

func (t Time) Now() time.Time

type TypeParser

type TypeParser func(typeRepresentation string) (reflect.Type, error)

TypeParser parses type string representation into reflect.Type

type Types

type Types struct{}

func (Types) IsBool

func (t Types) IsBool(value interface{}) bool

func (Types) IsFloat64

func (t Types) IsFloat64(value interface{}) bool

func (Types) IsInt

func (t Types) IsInt(value interface{}) bool

func (Types) IsString

func (t Types) IsString(value interface{}) bool

Jump to

Keyboard shortcuts

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