func getBaseArgs(e *straumur.Event, isUpdate bool) ([]interface{}, error) {

	//todo, check if e.Payload/e.KeyParams is string and valid json
	payload, err := json.Marshal(e.Payload)
	if err != nil {
		return nil, err
	}

	keyparams, err := json.Marshal(e.KeyParams)
	if err != nil {
		return nil, err
	}

	if isUpdate {

		return []interface{}{
			e.Key,
			keyparams,
			payload,
			e.Description,
			e.Importance,
			e.Origin,
		}, nil

	}
	t := time.Now()
	if e.Created.IsZero() {
		e.Created = t
	}
	e.Updated = t

	return []interface{}{
		e.Key,
		keyparams,
		e.Created,
		e.Updated,
		payload,
		e.Description,
		e.Importance,
		e.Origin,
	}, nil

}
Exemple #2
0
func TestSimpleEcho(t *testing.T) {

	echoOnce.Do(startEchoServer)

	url := fmt.Sprintf("ws://%s%s", echoServerAddr, "/event")
	conn, err := websocket.Dial(url, "", "http://localhost/")
	if err != nil {
		t.Errorf("WebSocket handshake error: %v", err)
		return
	}

	var event straumur.Event
	event.Description = "hello"
	if err := websocket.JSON.Send(conn, event); err != nil {
		t.Errorf("Write: %v", err)
	}
	if err := websocket.JSON.Receive(conn, &event); err != nil {
		t.Errorf("Read: %v", err)
	}
	if event.ID != 1 {
		t.Errorf("event: expected %d got %d", 1, event.ID)
	}
	if event.Description != "hello" {
		t.Errorf("event: expected %q got %q", "hello", event.Description)
	}
	if err := websocket.JSON.Send(conn, event); err != nil {
		t.Errorf("Write: %v", err)
	}
	if err := websocket.JSON.Receive(conn, &event); err != nil {
		t.Errorf("Read: %v", err)
	}
	if event.ID != 2 {
		t.Errorf("event: expected %d got %d", 2, event.ID)
	}
	conn.Close()
}
Exemple #3
0
// Converts a row to an event
func scanRow(row *sql.Rows, e *straumur.Event) error {

	var entities StringSlice
	var references StringSlice
	var actors StringSlice
	var tags StringSlice
	temp := []byte{}
	tempkey := []byte{}

	err := row.Scan(
		&e.ID,
		&e.Key,
		&tempkey,
		&e.Created,
		&e.Updated,
		&temp,
		&e.Description,
		&e.Importance,
		&e.Origin,
		&entities,
		&references,
		&actors,
		&tags)

	if err != nil {
		return err
	}

	var data interface{}
	err = json.Unmarshal(temp, &data)

	if err != nil {
		return err
	}

	var keydata interface{}
	err = json.Unmarshal(tempkey, &keydata)

	if err != nil {
		return err
	}

	e.Payload = data
	e.KeyParams = keydata
	e.Entities = entities
	e.OtherReferences = references
	e.Actors = actors
	e.Tags = tags

	return nil
}