Chore: Remove unused Go code (#28852)
* Chore: Remove more unused Go code Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -1,55 +1,12 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Events can be passed to external systems via for example AMQP
|
||||
// Treat these events as basically DTOs so changes has to be backward compatible
|
||||
|
||||
type Priority string
|
||||
|
||||
const (
|
||||
PRIO_DEBUG Priority = "DEBUG"
|
||||
PRIO_INFO Priority = "INFO"
|
||||
PRIO_ERROR Priority = "ERROR"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
type OnTheWireEvent struct {
|
||||
EventType string `json:"event_type"`
|
||||
Priority Priority `json:"priority"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Payload interface{} `json:"payload"`
|
||||
}
|
||||
|
||||
type EventBase interface {
|
||||
ToOnWriteEvent() *OnTheWireEvent
|
||||
}
|
||||
|
||||
func ToOnWriteEvent(event interface{}) (*OnTheWireEvent, error) {
|
||||
eventType := reflect.TypeOf(event).Elem()
|
||||
|
||||
wireEvent := OnTheWireEvent{
|
||||
Priority: PRIO_INFO,
|
||||
EventType: eventType.Name(),
|
||||
Payload: event,
|
||||
}
|
||||
|
||||
baseField := reflect.Indirect(reflect.ValueOf(event)).FieldByName("Timestamp")
|
||||
if baseField.IsValid() {
|
||||
wireEvent.Timestamp = baseField.Interface().(time.Time)
|
||||
} else {
|
||||
wireEvent.Timestamp = time.Now()
|
||||
}
|
||||
|
||||
return &wireEvent, nil
|
||||
}
|
||||
|
||||
type OrgCreated struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Id int64 `json:"id"`
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type TestEvent struct {
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func TestEventCreation(t *testing.T) {
|
||||
e := TestEvent{
|
||||
Timestamp: time.Unix(1231421123, 223),
|
||||
}
|
||||
|
||||
wire, err := ToOnWriteEvent(&e)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, e.Timestamp.Unix(), wire.Timestamp.Unix())
|
||||
assert.Equal(t, "TestEvent", wire.EventType)
|
||||
}
|
||||
Reference in New Issue
Block a user