Exemple #1
0
func parse(id int, b []byte, i interface{}) error {
	var m map[string]interface{}

	err := json.Unmarshal(b, &m)
	if err != nil {
		return err
	}
	m["Id"] = fmt.Sprintf("%d", id)

	return mapstructure.Decode(m, i)
}
Exemple #2
0
func (self *Resource) ToMessage() *messages.Resource {
	m := structs.Map(self)
	m["Id"] = self.Id.Hex()
	m["ProjectId"] = self.ProjectId.Hex()
	b, _ := json.Marshal(self.Fields)

	delete(m, "Fields")

	m["Fields"] = b
	//m["Type"] = self.Type.String()

	var out messages.Resource
	mapstructure.Decode(m, &out)

	return &out
}
Exemple #3
0
func NewResourceFromMsg(resource *messages.Resource) (*Resource, error) {

	m := structs.Map(resource)

	fields := m["Fields"]
	fmt.Printf("fields %v", fields)

	delete(m, "Fields")

	var out Resource
	err := mapstructure.Decode(m, &out)

	if err != nil {
		return nil, err
	}
	return &out, nil

}
Exemple #4
0
func (self *Database) Get(colName string, id string, result interface{}) error {
	col := self.db.Use(colName)

	i, e := strconv.Atoi(id)

	if e != nil {
		return e
	}

	item, err := col.Read(i)

	if err != nil || item == nil {
		return err
	}

	item["Id"] = fmt.Sprintf("%d", i)

	mapstructure.Decode(item, result)

	return nil
}
Exemple #5
0
func (self Message) To(args interface{}) error {
	return mapstructure.Decode(self, args)
}