package collect import ( "log" "testing" ) type ABC struct { A int64 `json:"a"` B string `json:"b"` C interface{} `json:"c"` } func TestArray2MapByKey(t *testing.T) { var abcs []*ABC = []*ABC{ {1, "2", 3}, {3, "1", 2}, } a := Array2MapByKey[string](abcs, "B") log.Printf("%##v", a) log.Println(len(a)) } func TestArray2MapByKeyTag(t *testing.T) { var abcs []*ABC = []*ABC{ {1, "2", 3}, {3, "1", 2}, } a := Array2MapByKeyTag[int64](abcs, "a") log.Printf("%##v", a) log.Println(len(a)) } func TestArrayColumnTag(t *testing.T) { var abcs []*ABC = []*ABC{ {1, "2", 3}, {3, "1", 2}, } a := ArrayColumnTag[string](abcs, "b") log.Printf("%##v", a) log.Println(len(a)) }