You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
stardb/reflect_test.go

45 lines
911 B
Go

package stardb
import (
"fmt"
"reflect"
"testing"
)
type Useless struct {
Leader string `db:"leader"`
Usable bool `db:"use"`
}
func Test_SetRefVal(t *testing.T) {
var hehe = Useless{
Leader: "no",
}
mmval := map[string]interface{}{
"leader": "hehe",
"use": true,
}
fmt.Printf("%+v\n", hehe)
fmt.Println(setRefValue(&hehe, "db", "leader", "sb"))
fmt.Printf("%+v\n", hehe)
fmt.Println(setAllRefValue(&hehe, "db", mmval))
fmt.Printf("%+v\n", hehe)
fmt.Println(getAllRefKey(hehe, "db"))
}
func Test_Ref(t *testing.T) {
var me []Useless
p := reflect.TypeOf(&me).Elem()
v := reflect.ValueOf(&me).Elem()
mmval := map[string]interface{}{
"leader": "hehe",
"use": true,
}
newVal := reflect.New(p)
val := reflect.New(p.Elem())
setAllRefValue(val.Interface(), "db", mmval)
mynum:= reflect.Append(newVal.Elem(), val.Elem())
v.Set(mynum)
fmt.Println(val.Interface(), me, v)
}