cms

package module
v0.0.0-...-ac808a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 9 Imported by: 0

README

CMS

Installation

go get -u github.com/gowool/cms

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	PageRouteCMS = "page_slug"

	PageAliasPrefix    = "_page_alias_"
	PageInternalPrefix = "_page_internal_"
	PageErrorPrefix    = PageInternalPrefix + "error_"
)

Variables

This section is empty.

Functions

func BuildTags

func BuildTags(name string, id int64, data ...string) []string

func BuildTagsByIDs

func BuildTagsByIDs(name string, data ...int64) []string

func PageAfterSave

func PageAfterSave(storage PageStorage) func(context.Context, *SaveEvent[*Page]) error

func PageBeforeSave

func PageBeforeSave(storage PageStorage) func(context.Context, *SaveEvent[*Page]) error

Types

type DeleteEvent

type DeleteEvent struct {
	IDs []int64
	// contains filtered or unexported fields
}

func NewDeleteEvent

func NewDeleteEvent(ids []int64, tags ...string) *DeleteEvent

func (*DeleteEvent) Tags

func (e *DeleteEvent) Tags() []string

type EventPageStorage

type EventPageStorage struct {
	*EventStorage[Page]
	BeforeFindByURL       Hook[*FindA3Event[int64, string, time.Time, Page]]
	AfterFindByURL        Hook[*FindA3Event[int64, string, time.Time, Page]]
	BeforeFindByRouteName Hook[*FindA3Event[int64, string, time.Time, Page]]
	AfterFindByRouteName  Hook[*FindA3Event[int64, string, time.Time, Page]]
	BeforeFindByPageAlias Hook[*FindA3Event[int64, string, time.Time, Page]]
	AfterFindByPageAlias  Hook[*FindA3Event[int64, string, time.Time, Page]]
	BeforeFindByParentID  Hook[*FindA2Event[int64, time.Time, []Page]]
	AfterFindByParentID   Hook[*FindA2Event[int64, time.Time, []Page]]
	// contains filtered or unexported fields
}

func NewEventPageStorage

func NewEventPageStorage(storage PageStorage) *EventPageStorage

func (*EventPageStorage) FindByPageAlias

func (s *EventPageStorage) FindByPageAlias(ctx context.Context, siteID int64, pageAlias string, date time.Time) (Page, error)

func (*EventPageStorage) FindByParentID

func (s *EventPageStorage) FindByParentID(ctx context.Context, parentID int64, date time.Time) ([]Page, error)

func (*EventPageStorage) FindByRouteName

func (s *EventPageStorage) FindByRouteName(ctx context.Context, siteID int64, routeName string, date time.Time) (Page, error)

func (*EventPageStorage) FindByURL

func (s *EventPageStorage) FindByURL(ctx context.Context, siteID int64, url string, date time.Time) (Page, error)

type EventSiteStorage

type EventSiteStorage struct {
	*EventStorage[Site]
	BeforeFindByHosts Hook[*FindA2Event[[]string, time.Time, []Site]]
	AfterFindByHosts  Hook[*FindA2Event[[]string, time.Time, []Site]]
	BeforeFindAll     Hook[*FindA0Event[[]Site]]
	AfterFindAll      Hook[*FindA0Event[[]Site]]
	// contains filtered or unexported fields
}

func NewEventSiteStorage

func NewEventSiteStorage(storage SiteStorage) *EventSiteStorage

func (*EventSiteStorage) FindAll

func (s *EventSiteStorage) FindAll(ctx context.Context) ([]Site, error)

func (*EventSiteStorage) FindByHosts

func (s *EventSiteStorage) FindByHosts(ctx context.Context, hosts []string, date time.Time) ([]Site, error)

type EventStorage

type EventStorage[T any] struct {
	Storage[T]

	SaveEventTags   func(*T) []string
	DeleteEventTags func(ids ...int64) []string

	BeforeCreate       Hook[*SaveEvent[*T]]
	AfterCreate        Hook[*SaveEvent[*T]]
	BeforeUpdate       Hook[*SaveEvent[*T]]
	AfterUpdate        Hook[*SaveEvent[*T]]
	BeforeDelete       Hook[*DeleteEvent]
	AfterDelete        Hook[*DeleteEvent]
	BeforeFindByID     Hook[*FindByIDEvent[T]]
	AfterFindByID      Hook[*FindByIDEvent[T]]
	BeforeFind         Hook[*FindEvent[T]]
	AfterFind          Hook[*FindEvent[T]]
	BeforeFindAndCount Hook[*FindAndCountEvent[T]]
	AfterFindAndCount  Hook[*FindAndCountEvent[T]]
}

func NewEventStorage

func NewEventStorage[T any](storage Storage[T], saveEventTags func(*T) []string, deleteEventTags func(ids ...int64) []string) *EventStorage[T]

func (*EventStorage[T]) Create

func (s *EventStorage[T]) Create(ctx context.Context, model *T) error

func (*EventStorage[T]) Delete

func (s *EventStorage[T]) Delete(ctx context.Context, ids ...int64) error

func (*EventStorage[T]) Find

func (s *EventStorage[T]) Find(ctx context.Context, criteria *cr.Criteria) ([]T, error)

func (*EventStorage[T]) FindAndCount

func (s *EventStorage[T]) FindAndCount(ctx context.Context, criteria *cr.Criteria) ([]T, int, error)

func (*EventStorage[T]) FindByID

func (s *EventStorage[T]) FindByID(ctx context.Context, id int64) (T, error)

func (*EventStorage[T]) Update

func (s *EventStorage[T]) Update(ctx context.Context, model *T) error

type EventTemplateStorage

type EventTemplateStorage struct {
	*EventStorage[Template]
	BeforeFindByCode Hook[*FindA2Event[string, time.Time, Template]]
	AfterFindByCode  Hook[*FindA2Event[string, time.Time, Template]]
	// contains filtered or unexported fields
}

func NewEventTemplateStorage

func NewEventTemplateStorage(storage TemplateStorage) *EventTemplateStorage

func (*EventTemplateStorage) FindByCode

func (s *EventTemplateStorage) FindByCode(ctx context.Context, code string, date time.Time) (Template, error)

type FindA0Event

type FindA0Event[R any] struct {
	Result R
}

type FindA1Event

type FindA1Event[A1, R any] struct {
	Arg1   A1
	Result R
}

type FindA2Event

type FindA2Event[A1, A2, R any] struct {
	Arg1   A1
	Arg2   A2
	Result R
}

type FindA3Event

type FindA3Event[A1, A2, A3, R any] struct {
	Arg1   A1
	Arg2   A2
	Arg3   A3
	Result R
}

type FindAndCountEvent

type FindAndCountEvent[T any] struct {
	Criteria *cr.Criteria
	Data     []T
	Count    int
}

type FindByIDEvent

type FindByIDEvent[T any] struct {
	ID    int64
	Model T
}

type FindEvent

type FindEvent[T any] struct {
	Criteria *cr.Criteria
	Data     []T
}

type Hook

type Hook[T any] interface {
	Trigger(context.Context, T, ...func(context.Context, T) error) error
}

type Meta

type Meta struct {
	Type    MetaType `json:"type,omitempty"`
	Key     string   `json:"key,omitempty"`
	Content string   `json:"content,omitempty"`
}

func (Meta) Equals

func (m Meta) Equals(another Meta) bool

type MetaType

type MetaType string
const (
	MetaName     MetaType = "name"
	MetaEquiv    MetaType = "http-equiv"
	MetaProperty MetaType = "property"
)

func (MetaType) String

func (t MetaType) String() string

type Page

type Page struct {
	ID             int64             `json:"id,omitempty"`
	SiteID         int64             `json:"site_id,omitempty"`
	ParentID       *int64            `json:"parent_id,omitempty"`
	Name           string            `json:"name,omitempty"`
	Title          string            `json:"title,omitempty"`
	RouteName      string            `json:"route_name,omitempty"`
	PageAlias      string            `json:"page_alias,omitempty"`
	Slug           string            `json:"slug,omitempty"`
	URL            string            `json:"url,omitempty"`
	CustomURL      string            `json:"custom_url,omitempty"`
	Javascript     string            `json:"javascript,omitempty"`
	Stylesheet     string            `json:"stylesheet,omitempty"`
	TemplateCode   string            `json:"template_code,omitempty"`
	Decorate       bool              `json:"decorate,omitempty"`
	Position       int               `json:"position,omitempty"`
	RequestMethods []string          `json:"request_methods,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	Site           *Site             `json:"site,omitempty"`
	Parent         *Page             `json:"parent,omitempty"`
	Children       []*Page           `json:"children,omitempty"`
	Metas          []Meta            `json:"metas,omitempty"`
	Metadata       map[string]any    `json:"metadata,omitempty"`
	Created        time.Time         `json:"created,omitempty"`
	Updated        time.Time         `json:"updated,omitempty"`
	Published      *time.Time        `json:"published,omitempty"`
	Expired        *time.Time        `json:"expired,omitempty"`
}

func (*Page) FixURL

func (p *Page) FixURL()

func (*Page) IsCMS

func (p *Page) IsCMS() bool

func (*Page) IsDynamic

func (p *Page) IsDynamic() bool

func (*Page) IsEnabled

func (p *Page) IsEnabled(now time.Time) bool

func (*Page) IsError

func (p *Page) IsError() bool

func (*Page) IsHybrid

func (p *Page) IsHybrid() bool

func (*Page) IsInternal

func (p *Page) IsInternal() bool

func (*Page) SetAlias

func (p *Page) SetAlias(pageAlias string)

func (*Page) SetError

func (p *Page) SetError(routeName string)

func (*Page) SetInternal

func (p *Page) SetInternal(routeName string)

func (*Page) String

func (p *Page) String() string

type PageDefaults

type PageDefaults interface {
	GetDefaults(ctx context.Context) (map[string]any, error)
	GetRouteDefaults(ctx context.Context, routeName string) (map[string]any, error)
}

type PageService

type PageService interface {
	CreateWithDefaults(ctx context.Context, defaults map[string]interface{}) (Page, error)
	Save(ctx context.Context, page *Page) error
	GetByID(ctx context.Context, id int64) (Page, error)
	GetByURL(ctx context.Context, siteID int64, url string) (Page, error)
	GetByRouteName(ctx context.Context, siteID int64, routeName string) (Page, error)
	GetByPageAlias(ctx context.Context, siteID int64, pageAlias string) (Page, error)
	GetChildren(ctx context.Context, parentID int64) ([]Page, error)
}

func NewPageService

func NewPageService(storage PageStorage, defaults PageDefaults) PageService

type PageStorage

type PageStorage interface {
	Storage[Page]
	// contains filtered or unexported methods
}

type SaveEvent

type SaveEvent[T any] struct {
	Model T
	// contains filtered or unexported fields
}

func NewSaveEvent

func NewSaveEvent[T any](model T, tags ...string) *SaveEvent[T]

func (*SaveEvent[T]) Tags

func (e *SaveEvent[T]) Tags() []string

type Site

type Site struct {
	ID           int64          `json:"id,omitempty"`
	Name         string         `json:"name,omitempty"`
	Title        string         `json:"title,omitempty"`
	Separator    string         `json:"separator,omitempty"`
	Host         string         `json:"host,omitempty"`
	Locale       string         `json:"locale,omitempty"`
	RelativePath string         `json:"relative_path,omitempty"`
	IsDefault    bool           `json:"is_default,omitempty"`
	Metas        []Meta         `json:"metas,omitempty"`
	Metadata     map[string]any `json:"metadata,omitempty"`
	Created      time.Time      `json:"created,omitempty"`
	Updated      time.Time      `json:"updated,omitempty"`
	Published    *time.Time     `json:"published,omitempty"`
	Expired      *time.Time     `json:"expired,omitempty"`
}

func (Site) IsEnabled

func (s Site) IsEnabled(now time.Time) bool

func (Site) IsLocalhost

func (s Site) IsLocalhost() bool

func (Site) String

func (s Site) String() string

func (Site) URL

func (s Site) URL() string

type SiteService

type SiteService interface {
	CreateLocalhost() Site
	Save(ctx context.Context, site *Site) error
	GetByID(ctx context.Context, id int64) (Site, error)
	GetByHost(ctx context.Context, host string) ([]Site, error)
	GetAll(ctx context.Context) ([]Site, error)
}

func NewSiteService

func NewSiteService(storage SiteStorage) SiteService

type SiteStorage

type SiteStorage interface {
	Storage[Site]
	// contains filtered or unexported methods
}

type Storage

type Storage[T any] interface {
	Create(ctx context.Context, model *T) error
	Update(ctx context.Context, model *T) error
	Delete(ctx context.Context, ids ...int64) error
	FindByID(ctx context.Context, id int64) (T, error)
	Find(ctx context.Context, criteria *cr.Criteria) ([]T, error)
	FindAndCount(ctx context.Context, criteria *cr.Criteria) ([]T, int, error)
}

type StubHook

type StubHook[T any] struct{}

func (StubHook[T]) Trigger

func (h StubHook[T]) Trigger(ctx context.Context, event T, oneOff ...func(context.Context, T) error) error

type Template

type Template struct {
	ID        int64        `json:"id,omitempty"`
	Code      string       `json:"code,omitempty"`
	Content   string       `json:"content,omitempty"`
	Type      TemplateType `json:"type,omitempty"`
	Created   time.Time    `json:"created,omitempty"`
	Updated   time.Time    `json:"updated,omitempty"`
	Published *time.Time   `json:"published,omitempty"`
	Expired   *time.Time   `json:"expired,omitempty"`
}

func (Template) ContentBytes

func (t Template) ContentBytes() []byte

func (Template) Enabled

func (t Template) Enabled(now time.Time) bool

func (Template) String

func (t Template) String() string

type TemplateService

type TemplateService interface {
	GetByID(ctx context.Context, id int64) (Template, error)
	GetByCode(ctx context.Context, code string) (Template, error)
	IsFresh(ctx context.Context, code string, t int64) (bool, error)
	Exists(ctx context.Context, code string) (bool, error)
}

func NewTemplateService

func NewTemplateService(storage TemplateStorage) TemplateService

type TemplateStorage

type TemplateStorage interface {
	Storage[Template]
	// contains filtered or unexported methods
}

type TemplateType

type TemplateType int
const (
	TemplateDB TemplateType = iota
	TemplateFS
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL