magicarray

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 9 Imported by: 0

README

magicarray

NO care type, no care struct, easy to sort and aggregation.similar with php array structure,easy to deal for data process. Coding shortly,process automatically. in magicarray, no nil forever.

go get github.com/lingdor/magicarray

Functions

Name Describe
Makeof Make a MagicArray instance from struct,slice,array,map
ValueofStruct Make a MagicArray instance from struct, performance better than Makeof.
ValueOfSlice Make a MagicArray instance from Slice or array, performance better than Makeof
ValueofStructs Make a MagicArray instance from Structs, performance better than Makeof
MustValueof Make a MagicArray instance like Makeof,If return error than panic.
Make Make a empty MagicArray instance
Equals Return If lenth equal and key and value equals
Max Get the maximum numberic value from the array
Min Get the minmum numeric value from the array
Sum Calculate sum the total numeric values from the array
In check value is in MagicArray
ToStringList translate the MagicArray to string array
ToIntList translate the MagicArray to integer array
ToAnyList translate the MagicArray to any type of array
ToMap translate the MagicArray to map
Column Pick the Column from the two-dimensional table data
Len Get length of the MagicArray
Get Get item from the MagicArray
Keys Get keys of the MagicArray
Values Get values of the MagicArray
Pick Pick the keys and values to a new MagicArray for parameter keys order
SetColumnTag Set tags of key column
WashColumn Wash the value of MagicArray column by rules
SetTag Set tag key and value to the value of MagicArray
WashAll Wash the value of MagicArray all values by rules
WashTagRuleJsonInitialLower Wash the value tags ,lower the initial letter if no fund the json tag
Merge Merge fields from parameters to MagicArray
Append Append value to Magic
Set Set value of MagicArray
Remove Remove item from the MagicArray

Hello world


package main

import (
	"encoding/json"
	"fmt"
	arr "github.com/lingdor/magicarray"
	"time"
)

type UserDTO struct {
	Id   int `json:"userid"`
	Name string
}

type ScoreDTO struct {
	Score     int
	ScoreTime time.Time
}

type AreaDto struct {
	CityId int
	City   string
}

func main() {

	user := UserDTO{
		Id:   1,
		Name: "bobby",
	}
	score := ScoreDTO{
		Score:     66,
		ScoreTime: time.Now(),
	}
	area := AreaDto{
		CityId: 10000,
		City:   "beij",
	}

	mix, _ := arr.Merge(arr.ValueofStruct(user), score, area)
	mix = arr.Pick(mix, "Id", "City", "Score")
	if bs, err := json.Marshal(mix); err == nil {
		fmt.Println(string(bs))
	} else {
		panic(err)
	}

}

output:

{"userid":1,"City":"beij","Score":66}

examples

More of examples, visit _examples/ in my repository.

thanks!

Documentation

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 Equals

func Equals(from MagicArray, to any) error

func GenerateNamingFormatter

func GenerateNamingFormatter(code int) func(string) string

func In added in v0.0.5

func In(arr MagicArray, value any) bool

In check value is in MagicArray

func Len

func Len(arr MagicArray) int

func ToAnyList added in v0.0.5

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 added in v0.0.5

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

Types

type MagicArray

type MagicArray api.MagicArray

func Append

func Append(arr MagicArray, val any) MagicArray

Append value to Magic

func Column

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

func Keys

func Keys(arr 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 added in v0.0.5

func MustValueof(list any) MagicArray

func Pick added in v0.0.5

func Pick(arr 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 added in v0.0.5

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

Set value of MagicArray

func SetColumnTag added in v0.0.5

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

SetColumnTag Set tags of key column

func SetTag added in v0.0.5

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 no thread sfae

func ValueofStruct

func ValueofStruct(val any) MagicArray

func ValueofStructs

func ValueofStructs(list any) (MagicArray, error)

func Values

func Values(arr MagicArray) MagicArray

func WashAll added in v0.0.5

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

WashAll Wash the value of MagicArray all values by rules

func WashColumn added in v0.0.5

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

WashColumn Wash the value of MagicArray column by rules

type Opt

type Opt func(arr MagicArray) MagicArray

type WashRuleFunc added in v0.0.5

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

WashRuleFunc type of wash rule function

func WashTagRuleJsonInitialLower added in v0.0.5

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(arr MagicArray) WriteMagicArray

type ZVal

type ZVal api.ZVal

func Get

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

func Max

func Max(arr MagicArray) ZVal

func Min

func Min(arr MagicArray) ZVal

func Sum

func Sum(arr MagicArray) ZVal

func ZValTagSet added in v0.0.5

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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