40 lines
798 B
Go
40 lines
798 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
|
||
|
package folio
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
type EventType string
|
||
|
|
||
|
const (
|
||
|
EventTypeLoad EventType = "load"
|
||
|
EventTypeCreate EventType = "create"
|
||
|
EventTypeRead EventType = "read"
|
||
|
EventTypeUpdate EventType = "update"
|
||
|
EventTypeDelete EventType = "delete"
|
||
|
EventTypeError EventType = "error"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
ErrUnknownEventType error = errors.New("Unknown EventType")
|
||
|
)
|
||
|
|
||
|
func (e EventType) Validate() (err error) {
|
||
|
switch e {
|
||
|
case EventTypeLoad, EventTypeCreate, EventTypeRead, EventTypeUpdate, EventTypeDelete, EventTypeError:
|
||
|
default:
|
||
|
return fmt.Errorf("%w: %s", ErrUnknownEventType, e)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (e *EventType) Set(v EventType) (err error) {
|
||
|
if err = v.Validate(); err == nil {
|
||
|
(*e) = v
|
||
|
}
|
||
|
return
|
||
|
}
|