本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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))
}
示例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())
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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))
}
}
示例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
}
示例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
}