Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterEvents(r event.Registry)
- type CreatedData
- type FieldsAddedData
- type FieldsRemovedData
- type Page
- func (p *Page) Add(fields ...field.Field) error
- func (p *Page) ApplyEvent(evt event.Event)
- func (p *Page) Create(name string) error
- func (p *Page) Field(name string) (field.Field, error)
- func (p *Page) MarshalJSON() ([]byte, error)
- func (p *Page) Remove(fields ...string) error
- func (p *Page) UnmarshalJSON(b []byte) error
- type Repository
Constants ¶
View Source
const ( // Created means a Page was created. Created = "cms.static.page.created" // FieldsAdded means Fields were added to a Page. FieldsAdded = "cms.static.page.fields_added" // FieldsRemoved means Fields were removed from a Page. FieldsRemoved = "cms.static.page.fields_removed" )
View Source
const Aggregate = "cms.static.page"
Aggregate is the name of the Page aggregate.
Variables ¶
View Source
var ( // ErrEmptyName is returned when trying to create a Page with an empty name. ErrEmptyName = errors.New("empty name") // ErrNotCreated is returned when trying to use a Page that wasn't created yet. ErrNotCreated = errors.New("page not created") // ErrDuplicateField is returned when adding a Field to a Page that already // has a Field with the same name. ErrDuplicateField = errors.New("duplicate field") // ErrFieldNotFound is returned when trying to get a Field of a Page that // doesn't exist in the Page. ErrFieldNotFound = errors.New("field not found") // ErrGuarded is retured when trying to remove a guarded Field from a Page. ErrGuarded = errors.New("guarded field") )
Functions ¶
func RegisterEvents ¶
RegisterEvents register events into a registry.
Types ¶
type CreatedData ¶
type CreatedData struct {
Name string
}
CreatedData is the event data for Created.
type FieldsAddedData ¶
FieldsAddedData is the event data for FieldsAdded.
type FieldsRemovedData ¶
type FieldsRemovedData struct {
Fields []string
}
FieldsRemovedData is the event data for FieldsRemoved.
type Page ¶
Page is a web page.
func Create ¶
Create creates the Page with the given name. Create(name, fields...) is a shortcut for
p := New(uuid.New())
err := p.Create("foo", fields...)
Fields passed to Create are added to the Page as guarded Fields that cannot be removed. To add removable Fields to a Page p, use p.Add instead:
p, _ := page.Create("foo")
p.Add(field.NewText(...), field.NewToggle(...))
func (*Page) ApplyEvent ¶
ApplyEvent applies aggregate events.
func (*Page) MarshalJSON ¶
func (*Page) UnmarshalJSON ¶
type Repository ¶
type Repository interface {
// Save saves a Page.
Save(context.Context, *Page) error
// Fetch fetches the Page with the given UUID.
Fetch(context.Context, uuid.UUID) (*Page, error)
// Delete deletes a Page.
Delete(context.Context, *Page) error
}
A Repository persists Pages.
func GoesRepository ¶
func GoesRepository(repo aggregate.Repository) Repository
GoesRepository returns a Repository that uses the provided aggregate repository under the hood.
Click to show internal directories.
Click to hide internal directories.