Add Operation interface

This commit is contained in:
2023-01-05 13:17:10 -08:00
parent cf871efc23
commit 4ecce09b73
2 changed files with 16 additions and 5 deletions

View File

@@ -32,9 +32,8 @@ type LemmyWebSocketMsg struct {
Data json.RawMessage `json:"data"`
}
// IsOneOf checks if the message is one of the given operation.
// Operations must be of type UserOperation or UserOperationCrud.
func (msg LemmyWebSocketMsg) IsOneOf(ops ...any) bool {
// IsOneOf checks if the message is one of the given operations.
func (msg LemmyWebSocketMsg) IsOneOf(ops ...Operation) bool {
for _, op := range ops {
switch op := op.(type) {
case UserOperation:
@@ -49,3 +48,15 @@ func (msg LemmyWebSocketMsg) IsOneOf(ops ...any) bool {
}
return false
}
type Operation interface {
Operation() string
}
func (u UserOperation) Operation() string {
return string(u)
}
func (u UserOperationCrud) Operation() string {
return string(u)
}