util

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EMPTY_STACK = "Empty Stack"
)

Variables

View Source
var (
	ErrorInputNil                         = errors.New("input is nil")
	ErrorInputNotNumber                   = errors.New("input is not a number")
	ErrorVariableDataKind                 = errors.New("unsupported variable data kind")
	ErrorUnsupportedDataKindConvertNumber = errors.New("unsupported data kind for number conversion")
	ErrorEndOfStack                       = errors.New("end of stack")
)
View Source
var RegStringWithVariable regexp.Regexp = *regexp.MustCompile(`\$\{([a-zA-Z\_]+\w*?)\}`)

Functions

func ConvertInterfaceNumberToFloat64 added in v0.4.2

func ConvertInterfaceNumberToFloat64(val interface{}) (float64, error)

json input value is always float64, convert to different numeric value based on out element kind

func ConvertInterfaceNumberToInt64 added in v0.4.2

func ConvertInterfaceNumberToInt64(val interface{}) (int64, error)

func EncodePrimitiveValue added in v0.4.0

func EncodePrimitiveValue(v interface{}) ([]byte, error)

func EncodeToJsonString added in v0.4.0

func EncodeToJsonString(input string) []byte

given non-ASCII UTF-8 strings encode it to json string align with RFC 7159

func FlattenJsonStructForUnmarshal added in v0.4.0

func FlattenJsonStructForUnmarshal(workItem reflect.Value) map[string]*JSONStructField

this is for Unmarshal, the main differences relies on the fact that when unmarshalling, we cannot use workItem's value and omityempty field to drop field that will be returned from here, as the values has not yet been unmarshal into the workItem

func IsNumberStartingCharacter

func IsNumberStartingCharacter(b byte) bool

func IsPrimitiveType added in v0.4.0

func IsPrimitiveType(value reflect.Value) bool

func IsSpaces

func IsSpaces(b byte) bool

func RemoveBytes added in v0.3.0

func RemoveBytes(b []byte, b2remove []byte) []byte

func RepairUTF8 added in v0.3.2

func RepairUTF8(s string) string

Types

type JSONStructField added in v0.4.0

type JSONStructField struct {
	FieldName    string
	FieldValue   reflect.Value
	FieldJsonTag *JsonTagOptions
	ExtendTag    *JsonExtendOptions
}

func FlattenJsonStructForMarshal added in v0.4.0

func FlattenJsonStructForMarshal(workItem reflect.Value) []*JSONStructField

FlattenJsonStruct flatten a struct into a list of JSONStructField, will drop field base on json tag settings, as the workItem already have all the information set.

func (*JSONStructField) ShouldDropFieldIfSetValue added in v0.4.0

func (j *JSONStructField) ShouldDropFieldIfSetValue(valueToUnmarshal reflect.Value) bool

type JsonExtendOptions added in v0.4.2

type JsonExtendOptions struct {
	FieldVariableKeyName   string
	FieldVariableValueName string
}

type JsonTagOptions added in v0.4.0

type JsonTagOptions struct {
	Omitempty    bool
	StringEncode bool
	// contains filtered or unexported fields
}

func GetFieldNameAndOptions added in v0.4.0

func GetFieldNameAndOptions(jsonTag string) *JsonTagOptions

type OrderedMap added in v0.4.0

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

func NewOrderedMap added in v0.4.0

func NewOrderedMap() *OrderedMap

func (*OrderedMap) Add added in v0.4.0

func (om *OrderedMap) Add(key string, value interface{})

Add a new key-value pair

func (*OrderedMap) Get added in v0.4.0

func (om *OrderedMap) Get(key string) (interface{}, bool)

Get the value for a key

func (*OrderedMap) Iterate added in v0.4.0

func (om *OrderedMap) Iterate(f func(key string, value interface{}))

Iterate through the key-value pairs in order

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any]() *Stack[T]

func (*Stack[T]) Clear added in v0.4.0

func (s *Stack[T]) Clear()

func (*Stack[T]) Clone added in v0.4.0

func (s *Stack[T]) Clone() *Stack[T]

func (*Stack[T]) Get added in v0.4.0

func (s *Stack[T]) Get(i int) (T, error)

func (*Stack[T]) GetSlice

func (s *Stack[T]) GetSlice() []T

func (*Stack[T]) IsEmpty added in v0.4.0

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) Length

func (s *Stack[T]) Length() int

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (T, error)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, error)

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

func (*Stack[T]) PushElements

func (s *Stack[T]) PushElements(v []T)

Jump to

Keyboard shortcuts

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