mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 12:57:34 +00:00
chore: move the go code into a subfolder
This commit is contained in:
66
apps/api/internal/v2/eventstore/event.go
Normal file
66
apps/api/internal/v2/eventstore/event.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package eventstore
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Unmarshal func(ptr any) error
|
||||
|
||||
type Payload interface {
|
||||
Unmarshal | any
|
||||
}
|
||||
|
||||
type Action[P Payload] struct {
|
||||
Creator string
|
||||
Type string
|
||||
Revision uint16
|
||||
Payload P
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
Action[any]
|
||||
UniqueConstraints []*UniqueConstraint
|
||||
}
|
||||
|
||||
type StorageEvent struct {
|
||||
Action[Unmarshal]
|
||||
|
||||
Aggregate Aggregate
|
||||
CreatedAt time.Time
|
||||
Position GlobalPosition
|
||||
Sequence uint32
|
||||
}
|
||||
|
||||
type Event[P any] struct {
|
||||
*StorageEvent
|
||||
Payload P
|
||||
}
|
||||
|
||||
func UnmarshalPayload[P any](unmarshal Unmarshal) (P, error) {
|
||||
var payload P
|
||||
err := unmarshal(&payload)
|
||||
return payload, err
|
||||
}
|
||||
|
||||
type EmptyPayload struct{}
|
||||
|
||||
type TypeChecker interface {
|
||||
ActionType() string
|
||||
}
|
||||
|
||||
func Type[T TypeChecker]() string {
|
||||
var t T
|
||||
return t.ActionType()
|
||||
}
|
||||
|
||||
func IsType[T TypeChecker](types ...string) bool {
|
||||
gotten := Type[T]()
|
||||
|
||||
for _, typ := range types {
|
||||
if gotten == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user