Example #1
0
func save(planetID string, changes []interface{}) {
	eventStore, err := filestore.FileStore(eventDataDirectory)
	failIf(err)
	for _, event := range changes {
		jsonEvent, err := json.Marshal(event)
		failIf(err)
		err = eventStore.Save("world", planetID, reflect.TypeOf(event).String(), []byte(jsonEvent))
		failIf(err)
	}
}
Example #2
0
func updateClaimHistory(claimantID string, changes []interface{}) {
	store, err := filestore.FileStore(dataStoreDirectory)
	failIf(err)
	for _, event := range changes {
		jsonEvent, err := json.Marshal(event)
		failIf(err)
		store.Save(claimantAggregateType, claimantID, reflect.TypeOf(event).String(), []byte(jsonEvent))
	}
	logEvents(changes, logFilePath)
}
Example #3
0
func updatePortsOfCallHistory(shipName string, changes []interface{}) {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}
	for _, event := range changes {
		jsonEvent, err := json.Marshal(event)
		failIf(err)
		store.Save("Ship", shipName, reflect.TypeOf(event).String(), []byte(jsonEvent))
	}
}
Example #4
0
func main() {
	eventStore, err := filestore.FileStore(eventDataDirectory)
	failIf(err)

	aggregateType := "Customer"
	aggregateID := "12345"
	eventType := "CustomerCreated"
	eventData := []byte("Bill Smith")
	err = eventStore.Save(aggregateType, aggregateID, eventType, eventData)
	failIf(err)

	eventHistory, err := eventStore.Get(aggregateType, aggregateID)
	failIf(err)

	fmt.Printf("Event: '%s' Event data: '%s'\n", eventHistory[0].Type, string(eventHistory[0].Data))
	// Output: Event: 'CustomerCreated' Event data: 'Bill Smith'
}
Example #5
0
func load(planetID string) *world {
	eventStore, err := filestore.FileStore(eventDataDirectory)
	failIf(err)
	eventHistory, err := eventStore.Get("world", planetID)
	failIf(err)

	var events []interface{}
	for _, item := range eventHistory {
		if item.Type == "main.worldCreated" {
			var event worldCreated
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
	}

	var planet world
	planet.loadFromHistory(events)
	return &planet
}
Example #6
0
func loadClaimHistory(claimantID string) []interface{} {
	// log.Printf("DEBUG loadClaimHistory for '%s:%s'", claimantAggregateType, claimantID)
	if strings.TrimSpace(claimantID) == "" {
		var emptyList []interface{}
		return emptyList
	}
	store, err := filestore.FileStore(dataStoreDirectory)
	failIf(err)

	eventHistory, err := store.Get(claimantAggregateType, claimantID)
	// log.Printf("DEBUG loadClaimHistory - found %d events.", len(eventHistory))
	failIf(err)
	var events []interface{}
	for _, item := range eventHistory {
		if item.Type == "stake.ClaimantCreated" {
			var event stake.ClaimantCreated
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "stake.ClaimantDeleted" {
			var event stake.ClaimantDeleted
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "stake.ClaimMade" {
			var event stake.ClaimMade
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "stake.ClaimRetracted" {
			var event stake.ClaimRetracted
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
	}
	return events
}
Example #7
0
func getPortsOfCallHistory(shipName string) []interface{} {
	var store hist.Eventstore
	var err error
	if useDynamo {
		store, err = dynamostore.DynamoStore(eventstoreTable, region, endpoint)
		failIf(err)
	} else {
		store, err = filestore.FileStore(dataStoreDirectory)
		failIf(err)
	}

	eventHistory, err := store.Get(shipAggregateType, shipName)
	failIf(err)

	var events []interface{}
	for _, item := range eventHistory {
		if item.Type == "ship.Registered" {
			var event ship.Registered
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Arrived" {
			var event ship.Arrived
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
		if item.Type == "ship.Departed" {
			var event ship.Departed
			err := json.Unmarshal(item.Data, &event)
			failIf(err)
			events = append(events, event)
		}
	}
	return events
}