array

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 14 Imported by: 5

Documentation

Overview

Package array is MagicArray main package, Users only import that package can use most features. You can use function to create MagicArray Instance: array.ValueofStruct array.ValueOfSlice array.ValueofStructs array.MustValueof array.ValueofMap array.Makeof

array.Makeof can create all supported types to create instance, but need reflect the types to calculate, so use the other will be quickly. but array.Makeof is more easily .

Index

Constants

View Source
const NamingDefault = NamingJsonFirst

NamingDefault use the order of Json,hump

View Source
const NamingGormFormat = 6
View Source
const NamingHump = 1

NamingHump Naming for the hump rule format,example: helloWord

View Source
const NamingJsonFirst = 51

NamingJson use the order of json,hump format

View Source
const NamingJsonFormat = 5
View Source
const NamingOrmFirst = 62

NamingOrm use order of gorm or underline split rule for naming

View Source
const NamingRaw = 3

NamingRaw Naming for raw value of rule

View Source
const NamingUnderLine = 2

NamingUnderLine Naming for the underline split words rule format, example: hello_world

Variables

This section is empty.

Functions

func Empty added in v0.0.7

func Empty(arr MagicArray) bool

func Equals

func Equals(from MagicArray, to any) error

func GenerateNamingFormatter

func GenerateNamingFormatter(code int) func(string) string

func Implode

func Implode(arr MagicArray, separatorChar string) string

Implode to join the values to a string

func In

func In(marr MagicArray, value any) bool

In check value is in MagicArray

func JosnOptOmitEmpty added in v0.0.7

func JosnOptOmitEmpty(isEmitEmtpty bool) api.JsonOpt

func JsonEncode added in v0.0.7

func JsonEncode(arr api.IMagicArray, writer io.Writer, opts ...api.JsonOpt) (err error)

func JsonMarshal added in v0.0.7

func JsonMarshal(arr api.IMagicArray, opts ...api.JsonOpt) ([]byte, error)

func JsonOptDefaultNamingUnderscoreToCamelCase added in v0.0.7

func JsonOptDefaultNamingUnderscoreToCamelCase() api.JsonOpt

func JsonOptIndent added in v0.0.7

func JsonOptIndent(size int) api.JsonOpt

func JsonOptIndent4 added in v0.0.7

func JsonOptIndent4() api.JsonOpt

func Len

func Len(marr MagicArray) int

func MaxLen added in v0.0.7

func MaxLen(marr MagicArray) int

func MustJsonMarshal added in v0.0.9

func MustJsonMarshal(arr api.IMagicArray, opts ...api.JsonOpt) []byte

func ToAnyList

func ToAnyList(array MagicArray) []any

func ToIntList

func ToIntList(array MagicArray) []int

func ToMap

func ToMap(array MagicArray) map[string]any

func ToStringList

func ToStringList(array MagicArray) []string

func ZValTagGet

func ZValTagGet(z ZVal, tag string) (string, bool)

Types

type MagicArray

type MagicArray = api.IMagicArray

MagicArray is type of Instance base interface. you can use this type to defined MagicArray objects. most of MagicArray functions supported MagicArray to in parameters.

func Append

func Append(arr MagicArray, val any) MagicArray

Append value to Magic

func Clone added in v0.0.11

func Clone(arr MagicArray) MagicArray

func Column

func Column(from MagicArray, key interface{}) MagicArray

func Explode

func Explode(str string, separatorChar string) MagicArray

Explode string to MagicArray

func JsonUnMarshal added in v0.0.11

func JsonUnMarshal(content []byte) (MagicArray, error)

func Keys

func Keys(marr MagicArray) MagicArray

func Make

func Make(isKeys, isSort bool, cap int) MagicArray

func Merge

func Merge(arr MagicArray, args ...any) (MagicArray, error)

Merge fields from parameters to MagicArray

func MustValueof

func MustValueof(list any) MagicArray

func NewArr added in v0.0.7

func NewArr[T any](vals ...T) MagicArray

NewArr MagicArray of array values

func Pick

func Pick(marr MagicArray, keys ...any) MagicArray

Pick Pick the keys and values to a new MagicArray for parameter keys order

func Remove

func Remove(arr MagicArray, keys ...any) MagicArray

Remove item from the MagicArray

func Set

func Set(arr MagicArray, key, val any) MagicArray

Set value of MagicArray

func SetColumnTag

func SetColumnTag(array MagicArray, columnKey any, tagk, tagv string) MagicArray

SetColumnTag Set tags of key column

func SetTag

func SetTag(arr MagicArray, key any, tagk, tagv string) MagicArray

SetTag Set tag key and value to the value of MagicArray

func ValueOfSlice

func ValueOfSlice[T any](val []T) MagicArray

func Valueof

func Valueof(list any) (ret MagicArray, err error)

Valueof make a instance of MagicArray (no thread safe)

func ValueofMap added in v0.0.7

func ValueofMap[T any](m map[string]T) MagicArray

func ValueofStruct

func ValueofStruct(val any) MagicArray

func ValueofStructs

func ValueofStructs(list any) (MagicArray, error)

func Values

func Values(marr MagicArray) MagicArray

func WashAll

func WashAll(arr MagicArray, rules ...WashRuleFunc) MagicArray

WashAll Wash the value of MagicArray all values by rules

func WashColumn

func WashColumn(array MagicArray, column string, rules ...WashRuleFunc) MagicArray

WashColumn Wash the value of MagicArray column by rules

type WashRuleFunc

type WashRuleFunc func(key, val ZVal) (ZVal, ZVal, bool)

WashRuleFunc type of wash rule function

func GetWashFuncWashUnderScoreCaseToCamelCase added in v0.0.7

func GetWashFuncWashUnderScoreCaseToCamelCase(firstUpper bool) WashRuleFunc

func GetWashKeysFuncWashUnderScoreCaseToCamelCase added in v0.0.7

func GetWashKeysFuncWashUnderScoreCaseToCamelCase(firstUpper bool) WashRuleFunc

func WashTagRuleJsonInitialLower

func WashTagRuleJsonInitialLower() WashRuleFunc

WashTagRuleJsonInitialLower Wash the value tags ,lower the initial letter if no fund the json tag.

type WriteMagicArray

type WriteMagicArray = api.WriteMagicArray

func ToWriter

func ToWriter(marr MagicArray) WriteMagicArray

type ZVal

type ZVal = api.IZVal

ZVal is the mixed value item of MagicArray, You can get int, string, bool etc. type of value by ZVal. for example: zval.String() zval.IsEmpty() zval.IsNil zval.Int() zval.Arr() ...

func Get

func Get(marr MagicArray, key interface{}) ZVal

func Max

func Max(marr MagicArray) ZVal

func Min

func Min(marr MagicArray) ZVal

func Sum

func Sum(marr MagicArray) ZVal

func ZValTagSet

func ZValTagSet(z ZVal, tag, val string) ZVal

Jump to

Keyboard shortcuts

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