jx/internal/folio/eventtype.go
Matthew Rich a73acb8b93
Some checks failed
Lint / golangci-lint (push) Failing after 9m55s
Declarative Tests / test (push) Failing after 17s
add resource event handler types
2024-10-09 23:03:52 +00:00

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
}