当前位置: 首页>>代码示例>>Golang>>正文


Golang Raw.Unmarshal方法代码示例

本文整理汇总了Golang中gopkg/in/mgo/v2/bson.Raw.Unmarshal方法的典型用法代码示例。如果您正苦于以下问题:Golang Raw.Unmarshal方法的具体用法?Golang Raw.Unmarshal怎么用?Golang Raw.Unmarshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gopkg/in/mgo/v2/bson.Raw的用法示例。


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

示例1: SetBSON

// SetBSON allows us to use dependency representation of both
// just task Ids and of true Dependency structs.
//  TODO eventually drop all of this switching
func (d *Dependency) SetBSON(raw bson.Raw) error {
	// copy the Dependency type to remove this SetBSON method but preserve bson struct tags
	type nakedDep Dependency
	var depCopy nakedDep
	if err := raw.Unmarshal(&depCopy); err == nil {
		if depCopy.TaskId != "" {
			*d = Dependency(depCopy)
			return nil
		}
	}

	// hack to support the legacy depends_on, since we can't just unmarshal a string
	strBytes, _ := bson.Marshal(bson.RawD{{"str", raw}})
	var strStruct struct {
		String string `bson:"str"`
	}
	if err := bson.Unmarshal(strBytes, &strStruct); err == nil {
		if strStruct.String != "" {
			d.TaskId = strStruct.String
			d.Status = evergreen.TaskSucceeded
			return nil
		}
	}

	return bson.SetZero
}
开发者ID:pritten,项目名称:evergreen,代码行数:29,代码来源:task.go

示例2: SetBSON

// SetBSON implements bson.Setter
func (l *Level) SetBSON(raw bson.Raw) (err error) {
	var t bsonLevel
	err = raw.Unmarshal(&t)
	if err != nil {
		return err
	}
	m := map[Level]bool{
		Level(0400): t.UserCanRead,
		Level(0200): t.UserCanWrite,
		Level(0100): t.UserCanExecute,
		Level(0040): t.GroupCanWrite,
		Level(0020): t.GroupCanRead,
		Level(0010): t.GroupCanExecute,
		Level(0004): t.OtherCanRead,
		Level(0002): t.OtherCanWrite,
		Level(0001): t.OtherCanExecute,
	}
	for p, b := range m {
		if !b {
			continue
		}
		*l = *l | p
	}
	return
}
开发者ID:codeblanche,项目名称:golibs,代码行数:26,代码来源:level.go

示例3: SetBSON

func (s *getterSetterD) SetBSON(raw bson.Raw) error {
	var doc bson.D
	err := raw.Unmarshal(&doc)
	doc = append(doc, bson.DocElem{"suffix", true})
	*s = getterSetterD(doc)
	return err
}
开发者ID:devsaurin,项目名称:mongo-tools,代码行数:7,代码来源:bson_test.go

示例4: SetBSON

func (t *TimePeriod) SetBSON(raw bson.Raw) error {
	var str string
	err := raw.Unmarshal(&str)
	if err == nil {
		str = strings.Replace(str, "\"", "", -1)
		split := strings.Split(str, "/")

		if len(split) == 2 {
			t.FromTime, err = time.Parse(STD_TIME_FORMAT_PERIOD, split[0])
			if err != nil {
				return err
			}
			t.ToTime, err = time.Parse(STD_TIME_FORMAT_PERIOD, split[1])
			if err != nil {
				return err
			}
		} else {
			t.FromTime, err = time.Parse(STD_TIME_FORMAT_INSTANT, split[0])
			if err != nil {
				return err
			}
		}
	}
	return err
}
开发者ID:zubairhamed,项目名称:gossamer,代码行数:25,代码来源:time.go

示例5: TestUnmarshalRawNil

func (s *S) TestUnmarshalRawNil(c *C) {
	// Regression test: shouldn't try to nil out the pointer itself,
	// as it's not settable.
	raw := bson.Raw{0x0A, []byte{}}
	err := raw.Unmarshal(&struct{}{})
	c.Assert(err, IsNil)
}
开发者ID:devsaurin,项目名称:mongo-tools,代码行数:7,代码来源:bson_test.go

示例6: SetBSON

func (id *UUID) SetBSON(raw bson.Raw) error {
	var s string
	if err := raw.Unmarshal(&s); err != nil {
		return err
	}
	return id.UnmarshalText([]byte(s))
}
开发者ID:h12w,项目名称:uuid,代码行数:7,代码来源:bson.go

示例7: SetBSON

// SetBSON is a workaround for bson.Marshal not allowing
// for pointers to structs with ,inline option.
// It fails with:
//
//   Option ,inline needs a struct value or map field
//
// It should eventually be fixed and workaround dropped.
func (in *Inliner) SetBSON(raw bson.Raw) error {
	if err := raw.Unmarshal(in.SecondAddr()); err != nil {
		return err
	}

	return raw.Unmarshal(in.FirstAddr())
}
开发者ID:koding,项目名称:koding,代码行数:14,代码来源:inliner.go

示例8: SetBSON

func (id *eventID) SetBSON(raw bson.Raw) error {
	err := raw.Unmarshal(&id.Target)
	if err != nil {
		return raw.Unmarshal(&id.ObjId)
	}
	return nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:7,代码来源:event.go

示例9: SetBSON

func (d *DateTime) SetBSON(raw bson.Raw) error {
	var tm time.Time
	if err := raw.Unmarshal(&tm); err != nil {
		return err
	}
	*d = DateTime(tm)
	return nil
}
开发者ID:rafalbigaj,项目名称:logo-spy,代码行数:8,代码来源:logo-spy.go

示例10: SetBSON

func (m *settingsMap) SetBSON(raw bson.Raw) error {
	rawMap := make(map[string]interface{})
	if err := raw.Unmarshal(rawMap); err != nil {
		return err
	}
	replaceKeys(rawMap, unescapeReplacer.Replace)
	*m = settingsMap(rawMap)
	return nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:9,代码来源:settings.go

示例11: SetBSON

func (t *RFC2822Time) SetBSON(raw bson.Raw) error {
	var result time.Time
	err := raw.Unmarshal(&result)
	if err != nil {
		return err
	}
	*t = RFC2822Time(result)
	return nil
}
开发者ID:russellhaering,项目名称:godep-timetools-bug,代码行数:9,代码来源:rfc2822time.go

示例12: SetBSON

func (t *Timestamp) SetBSON(raw bson.Raw) error {
	var s string
	err := raw.Unmarshal(&s)
	if err != nil {
		return err
	}
	*t, err = ParseTimestamp(s)
	return err
}
开发者ID:ehengzh,项目名称:ctpd,代码行数:9,代码来源:timestamp.go

示例13: TestUnmarshalRawStructItems

func (s *S) TestUnmarshalRawStructItems(c *C) {
	for i, item := range structItems {
		raw := bson.Raw{0x03, []byte(wrapInDoc(item.data))}
		zero := makeZeroDoc(item.obj)
		err := raw.Unmarshal(zero)
		c.Assert(err, IsNil)
		c.Assert(zero, DeepEquals, item.obj, Commentf("Failed on item %d: %#v", i, item))
	}
}
开发者ID:devsaurin,项目名称:mongo-tools,代码行数:9,代码来源:bson_test.go

示例14: SetBSON

func (d *DurationString) SetBSON(raw bson.Raw) error {
	var s string
	err := raw.Unmarshal(&s)
	if err != nil || s == "" {
		d.Duration = 0
		return err
	}
	d.Duration, err = time.ParseDuration(s)
	return err
}
开发者ID:jmptrader,项目名称:mup,代码行数:10,代码来源:plugin.go

示例15: SetBSON

func (l *List) SetBSON(raw bson.Raw) error {
	var m struct {
		Sample *Node `bson:"sample"`
	}
	if err := raw.Unmarshal(&m); err != nil {
		return err
	}
	l.sample = m.Sample
	return nil
}
开发者ID:rachelguerin,项目名称:talks,代码行数:10,代码来源:list.go


注:本文中的gopkg/in/mgo/v2/bson.Raw.Unmarshal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。