Ejemplo n.º 1
0
func (e *Event) MarshalJSON() ([]byte, error) {
	m := map[string]interface{}{
		"Type":      e.Type,
		"Entity":    e.Entity,
		"Attribute": e.Attribute,
	}

	if e.Before != nil {
		m["Before"] = map[string]interface{}{
			"Operation":   e.Before.Operation,
			"Domain":      e.Before.Domain,
			"Value":       e.Before.Value,
			"Time":        chrono.JSON(e.Before.Time),
			"Transaction": e.Before.Transaction,
		}
	}

	if e.After != nil {
		m["After"] = map[string]interface{}{
			"Operation":   e.After.Operation,
			"Domain":      e.After.Domain,
			"Value":       e.After.Value,
			"Time":        chrono.JSON(e.After.Time),
			"Transaction": e.After.Transaction,
		}
	}

	return json.Marshal(m)
}
Ejemplo n.º 2
0
Archivo: fact.go Proyecto: l-k-/origins
func (f *Fact) MarshalJSON() ([]byte, error) {
	var tx interface{}

	if f.Transaction > 0 {
		tx = f.Transaction
	}

	return json.Marshal(map[string]interface{}{
		"Operation":   f.Operation,
		"Domain":      f.Domain,
		"Entity":      f.Entity,
		"Attribute":   f.Attribute,
		"Value":       f.Value,
		"Time":        chrono.JSON(f.Time),
		"Transaction": tx,
	})
}