• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang bson.StructToBson函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/davidli2010/gobson_exp/bson.StructToBson函数的典型用法代码示例。如果您正苦于以下问题:Golang StructToBson函数的具体用法?Golang StructToBson怎么用?Golang StructToBson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了StructToBson函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestStructMapPointerStruct

func TestStructMapPointerStruct(t *testing.T) {
	type mst struct {
		Map *map[string]interface{}
	}

	type st struct {
		M *mst
	}

	m := st{
		&mst{&mdata},
	}

	b := bson.StructToBson(&m)

	var m2 st
	b.Struct(&m2)

	if len(*(m.M.Map)) != len(*(m2.M.Map)) {
		t.Errorf("invalid struct map pointer mapping")
	}

	for k, v := range *(m.M.Map) {
		v2, exist := (*(m2.M.Map))[k]
		if !exist {
			t.Errorf("invalid struct map pointer mapping")
		}

		if !valueEqual(v, v2) {
			t.Errorf("invalid struct map pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:33,代码来源:struct_test.go


示例2: TestInterfaceNilPointerStruct

func TestInterfaceNilPointerStruct(t *testing.T) {
	type ptr struct {
		Bool    *interface{}
		Int     *interface{}
		Int8    *interface{}
		Int16   *interface{}
		Int32   *interface{}
		Int64   *interface{}
		Uint    *interface{}
		Uint8   *interface{}
		Uint16  *interface{}
		Uint32  *interface{}
		Uint64  *interface{}
		Uintptr *interface{}
		Float32 *interface{}
		Float64 *interface{}
		String  *interface{}
	}

	p := ptr{}

	var p2 ptr
	b := bson.StructToBson(p)
	b.Struct(&p2)

	if p != p2 {
		t.Errorf("invalid interface nil pointer mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:29,代码来源:struct_test.go


示例3: TestStructDocStruct

func TestStructDocStruct(t *testing.T) {
	type dst struct {
		Doc bson.Doc
	}

	type st struct {
		D dst
	}

	d := st{
		dst{ddata},
	}

	b := bson.StructToBson(&d)

	var d2 st
	b.Struct(&d2)

	if len(d.D.Doc) != len(d2.D.Doc) {
		t.Errorf("invalid struct doc mapping")
	}

	for i := 0; i < len(d.D.Doc); i++ {
		e := d.D.Doc[i]
		e2 := d2.D.Doc[i]

		if e.Name != e2.Name {
			t.Errorf("invalid struct doc mapping")
		}

		if !valueEqual(e.Value, e2.Value) {
			t.Errorf("invalid struct doc mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:35,代码来源:struct_test.go


示例4: TestPrimaryDocPointerStruct

func TestPrimaryDocPointerStruct(t *testing.T) {
	type dst struct {
		Doc *bson.Doc
	}

	d := dst{&ddata}

	b := bson.StructToBson(&d)

	var d2 dst
	b.Struct(&d2)

	if len(*d.Doc) != len(*d2.Doc) {
		t.Errorf("invalid primary doc pointer mapping")
	}

	for i := 0; i < len(*d.Doc); i++ {
		e := (*d.Doc)[i]
		e2 := (*d2.Doc)[i]

		if e.Name != e2.Name {
			t.Errorf("invalid primary doc pointer mapping")
		}

		if !valueEqual(e.Value, e2.Value) {
			t.Errorf("invalid primary doc pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:29,代码来源:struct_test.go


示例5: TestPrimaryMapPointerStruct

func TestPrimaryMapPointerStruct(t *testing.T) {
	type mst struct {
		Map *map[string]interface{}
	}

	m := mst{&mdata}

	b := bson.StructToBson(&m)

	var m2 mst
	b.Struct(&m2)

	if len(*m.Map) != len(*m2.Map) {
		t.Errorf("invalid primary map pointer mapping")
	}

	for k, v := range *m.Map {
		v2, exist := (*m2.Map)[k]
		if !exist {
			t.Errorf("invalid primary map pointer mapping")
		}

		if !valueEqual(v, v2) {
			t.Errorf("invalid primary map pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:27,代码来源:struct_test.go


示例6: TestPrimaryArraySliceStruct

func TestPrimaryArraySliceStruct(t *testing.T) {
	type as struct {
		Array [3]int
		Slice []string
	}

	a := as{
		Array: [3]int{math.MinInt32, 0, math.MaxInt32},
		Slice: []string{"hello", "world"},
	}

	b := bson.StructToBson(a)

	var a2 as
	b.Struct(&a2)

	if a.Array != a2.Array {
		t.Errorf("invalid primary array mapping")
	}

	if len(a.Slice) != len(a2.Slice) {
		t.Errorf("invalid primary slice mapping")
	}

	for i := 0; i < len(a.Slice); i++ {
		if a.Slice[i] != a2.Slice[i] {
			t.Errorf("invalid primary slice mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:30,代码来源:struct_test.go


示例7: TestPrimaryArraySlicePointerStruct

func TestPrimaryArraySlicePointerStruct(t *testing.T) {
	type as struct {
		Array *[3]int
		Slice *[]string
	}

	Array := [3]int{math.MinInt32, 0, math.MaxInt32}
	Slice := []string{"hello", "world"}

	a := as{
		Array: &Array,
		Slice: &Slice,
	}

	b := bson.StructToBson(a)

	var a2 as
	b.Struct(&a2)

	if *a.Array != *a2.Array {
		t.Errorf("invalid primary array pointer mapping")
	}

	if len(*a.Slice) != len(*a2.Slice) {
		t.Errorf("invalid primary slice pointer mapping")
	}

	for i := 0; i < len(*a.Slice); i++ {
		if (*a.Slice)[i] != (*a2.Slice)[i] {
			t.Errorf("invalid primary slice pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:33,代码来源:struct_test.go


示例8: TestStructDocPointerStruct

func TestStructDocPointerStruct(t *testing.T) {
	type dst struct {
		Doc *bson.Doc
	}

	type st struct {
		D *dst
	}

	d := st{
		&dst{&ddata},
	}

	b := bson.StructToBson(&d)

	var d2 st
	b.Struct(&d2)

	if len(*(d.D.Doc)) != len(*(d2.D.Doc)) {
		t.Errorf("invalid struct doc pointer mapping")
	}

	for i := 0; i < len(*(d.D.Doc)); i++ {
		e := (*(d.D.Doc))[i]
		e2 := (*(d2.D.Doc))[i]

		if e.Name != e2.Name {
			t.Errorf("invalid struct doc pointer mapping")
		}

		if !valueEqual(e.Value, e2.Value) {
			t.Errorf("invalid struct doc pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:35,代码来源:struct_test.go


示例9: TestArraySliceStructStruct

func TestArraySliceStructStruct(t *testing.T) {
	type st struct {
		Array [3]primary
		Slice []primary
	}

	s := st{
		Array: [3]primary{pridata, pridata, pridata},
		Slice: []primary{pridata, pridata, pridata},
	}

	b := bson.StructToBson(&s)

	var s2 st
	b.Struct(&s2)

	if s2.Array != s.Array {
		t.Errorf("invalid array struct mapping")
	}

	if len(s2.Slice) != len(s.Slice) {
		t.Fatalf("invalid slice struct mapping")
	}

	for i := 0; i < len(s.Slice); i++ {
		p := s.Slice[i]
		p2 := s2.Slice[i]

		if p != p2 {
			t.Errorf("invalid slice struct mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:33,代码来源:struct_test.go


示例10: BenchmarkSdbBsonStruct

func BenchmarkSdbBsonStruct(t *testing.B) {
	for i := 0; i < t.N; i++ {
		s := pridata
		b := bson.StructToBson(s)

		//var s2 primary
		//b.Struct(&s2)
		_ = b
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:10,代码来源:struct_test.go


示例11: TestPrimaryNilPointerStruct

func TestPrimaryNilPointerStruct(t *testing.T) {
	p := primaryPtr{}

	var p2 primaryPtr
	bson.StructToBson(p).Struct(&p2)

	if p != p2 {
		t.Errorf("invalid primary nil pointer mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:10,代码来源:struct_test.go


示例12: TestInterfaceStruct

func TestInterfaceStruct(t *testing.T) {
	type primary struct {
		Bool    interface{}
		Int     interface{}
		Int8    interface{}
		Int16   interface{}
		Int32   interface{}
		Int64   interface{}
		Uint    interface{}
		Uint8   interface{}
		Uint16  interface{}
		Uint32  interface{}
		Uint64  interface{}
		Uintptr interface{}
		Float32 interface{}
		Float64 interface{}
		String  interface{}
	}

	s := primary{
		Bool:    true,
		Int:     math.MinInt32,
		Int8:    math.MinInt8,
		Int16:   math.MinInt16,
		Int32:   math.MinInt32,
		Int64:   math.MinInt64,
		Uint:    math.MaxUint32,
		Uint8:   math.MaxUint8,
		Uint16:  math.MaxUint16,
		Uint32:  math.MaxUint32,
		Uint64:  math.MaxInt64,
		Uintptr: math.MaxInt32,
		Float32: math.MaxFloat32,
		Float64: math.MaxFloat64,
		String:  "string",
	}

	b := bson.StructToBson(s)

	var s2 primary
	b.Struct(&s2)

	value := reflect.ValueOf(s)
	value2 := reflect.ValueOf(s2)
	typ := reflect.TypeOf(primary{})
	for i := 0; i < typ.NumField(); i++ {
		f := value.Field(i).Interface()
		f2 := value2.Field(i).Interface()

		if !valueEqual(f, f2) {
			t.Errorf("invalid interface mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:54,代码来源:struct_test.go


示例13: TestPrimaryStruct

func TestPrimaryStruct(t *testing.T) {
	s := pridata

	b := bson.StructToBson(s)

	var s2 primary
	b.Struct(&s2)

	if s != s2 {
		t.Errorf("invalid primary type mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:12,代码来源:struct_test.go


示例14: TestPrimaryPointerStruct

func TestPrimaryPointerStruct(t *testing.T) {
	Bool := true
	Int := int(math.MinInt32)
	Int8 := int8(math.MinInt8)
	Int16 := int16(math.MinInt16)
	Int32 := int32(math.MinInt32)
	Int64 := int64(math.MinInt64)
	Uint := uint(math.MaxUint32)
	Uint8 := uint8(math.MaxUint8)
	Uint16 := uint16(math.MaxUint16)
	Uint32 := uint32(math.MaxUint32)
	Uint64 := uint64(math.MaxInt64)
	Uintptr := uintptr(math.MaxInt32)
	Float32 := float32(math.MaxFloat32)
	Float64 := float64(math.MaxFloat64)
	String := "string"

	p := primaryPtr{
		Bool:    &Bool,
		Int:     &Int,
		Int8:    &Int8,
		Int16:   &Int16,
		Int32:   &Int32,
		Int64:   &Int64,
		Uint:    &Uint,
		Uint8:   &Uint8,
		Uint16:  &Uint16,
		Uint32:  &Uint32,
		Uint64:  &Uint64,
		Uintptr: &Uintptr,
		Float32: &Float32,
		Float64: &Float64,
		String:  &String,
	}

	var p2 primaryPtr
	bson.StructToBson(p).Struct(&p2)

	value := reflect.ValueOf(p)
	value2 := reflect.ValueOf(p2)
	typ := reflect.TypeOf(primaryPtr{})
	for i := 0; i < typ.NumField(); i++ {
		f := value.Field(i).Interface()
		f2 := value2.Field(i).Interface()

		if !valueEqual(f, f2) {
			t.Errorf("invalid primary pointer mapping")
		}
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:50,代码来源:struct_test.go


示例15: TestPrimaryMapNilPointerStruct

func TestPrimaryMapNilPointerStruct(t *testing.T) {
	type mst struct {
		Map *map[string]interface{}
	}

	m := mst{}

	b := bson.StructToBson(&m)

	var m2 mst
	b.Struct(&m2)

	if m != m2 {
		t.Errorf("invalid primary map nil pointer mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:16,代码来源:struct_test.go


示例16: TestPrimaryDocNilPointerStruct

func TestPrimaryDocNilPointerStruct(t *testing.T) {
	type dst struct {
		Doc *bson.Doc
	}

	d := dst{}

	b := bson.StructToBson(&d)

	var d2 dst
	b.Struct(&d2)

	if d != d2 {
		t.Errorf("invalid nil doc mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:16,代码来源:struct_test.go


示例17: TestStructNilPointerStruct

func TestStructNilPointerStruct(t *testing.T) {
	type st struct {
		Primary *primary
	}

	s := st{}

	b := bson.StructToBson(s)

	var s2 st
	b.Struct(&s2)

	if s != s2 {
		t.Errorf("invalid struct nil pointer struct mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:16,代码来源:struct_test.go


示例18: TestPrimaryArraySliceNilPointerStruct

func TestPrimaryArraySliceNilPointerStruct(t *testing.T) {
	type as struct {
		Array *[3]int
		Slice *[]string
	}

	a := as{}

	b := bson.StructToBson(a)

	var a2 as
	b.Struct(&a2)

	if a != a2 {
		t.Errorf("invalid primary array pointer mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:17,代码来源:struct_test.go


示例19: TestStructPointerStruct

func TestStructPointerStruct(t *testing.T) {
	type st struct {
		Primary *primary
	}

	s := st{
		Primary: &pridata,
	}

	b := bson.StructToBson(s)

	var s2 st
	b.Struct(&s2)

	if *s.Primary != *s2.Primary {
		t.Errorf("invalid struct pointer struct mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:18,代码来源:struct_test.go


示例20: TestStructStruct

func TestStructStruct(t *testing.T) {
	type st struct {
		Primary primary
	}

	s := st{
		Primary: pridata,
	}

	b := bson.StructToBson(s)

	var s2 st
	b.Struct(&s2)

	if s.Primary != s2.Primary {
		t.Errorf("invalid struct struct mapping")
	}
}
开发者ID:DavidLi2010,项目名称:gobson_exp,代码行数:18,代码来源:struct_test.go



注:本文中的github.com/davidli2010/gobson_exp/bson.StructToBson函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cellnet.BuildPacket函数代码示例发布时间:2022-05-23
下一篇:
Golang sophie.FsPath类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap