37 lines
878 B
Go
37 lines
878 B
Go
package codec_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"go_dreamfactory/lego/sys/codec"
|
|
"go_dreamfactory/lego/sys/log"
|
|
)
|
|
|
|
type TestData struct {
|
|
Name string
|
|
Value int
|
|
Array []interface{}
|
|
Data map[string]interface{}
|
|
}
|
|
type Test1Data struct {
|
|
Name string
|
|
Value int
|
|
}
|
|
|
|
func Test_sys(t *testing.T) {
|
|
if err := log.OnInit(nil); err != nil {
|
|
fmt.Printf("log init err:%v", err)
|
|
return
|
|
}
|
|
if sys, err := codec.NewSys(); err != nil {
|
|
fmt.Printf("gin init err:%v", err)
|
|
} else {
|
|
d, err := sys.MarshalJson(&TestData{Name: "http://liwei1dao.com?asd=1&dd=1", Value: 10, Array: []interface{}{1, "dajiahao", &Test1Data{Name: "liwe1dao", Value: 123}}, Data: map[string]interface{}{"hah": 1, "asd": 999}})
|
|
fmt.Printf("codec Marshal d:%s err:%v", d, err)
|
|
data := &TestData{}
|
|
err = sys.UnmarshalJson(d, data)
|
|
fmt.Printf("codec UnmarshalJson data:%v err:%v", data, err)
|
|
}
|
|
}
|