pages

package module
v0.0.0-...-72e02f8 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 24 Imported by: 0

README

Pages

Pages is a lightweight toolset for creating and managing web pages and templates with ease and flexibility.

Installation

go get -u github.com/gowool/pages

License

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInternal     = errors.New("internal server error")
	ErrSiteNotFound = errors.New("site not found")
	ErrPageNotFound = errors.New("page not found")
	ErrMenuNotFound = errors.New("menu not found")
)

Functions

func BuildTree

func BuildTree(nodes []model.Node, id int64) *model.Node

func CtxData

func CtxData(ctx context.Context) map[string]any

func CtxDebug

func CtxDebug(ctx context.Context) bool

func CtxEditor

func CtxEditor(ctx context.Context) bool

func CtxPage

func CtxPage(ctx context.Context) *model.Page

func CtxSEO

func CtxSEO(ctx context.Context) seo.SEO

func CtxSite

func CtxSite(ctx context.Context) *model.Site

func CtxURL

func CtxURL(ctx context.Context) url.URL

func Host

func Host(r *http.Request) string

func IsAjax

func IsAjax(r *http.Request) bool

func IsOneOfNotFound

func IsOneOfNotFound(err error) bool

func IsTLS

func IsTLS(r *http.Request) bool

func IsTextHTML

func IsTextHTML(header http.Header) bool

func Languages

func Languages(r *http.Request) []string

func MediaType

func MediaType(header http.Header) string

func PageDecorate

func PageDecorate(w http.ResponseWriter) bool

func PageNotDecorate

func PageNotDecorate(w http.ResponseWriter) bool

func Scheme

func Scheme(r *http.Request) string

func SetSkipSelectPage

func SetSkipSelectPage(ctx context.Context) context.Context

func SetSkipSelectSite

func SetSkipSelectSite(ctx context.Context) context.Context

func SkipSelectPage

func SkipSelectPage(ctx context.Context) bool

func SkipSelectSite

func SkipSelectSite(ctx context.Context) bool

func WithData

func WithData(ctx context.Context, data map[string]any) context.Context

func WithDebug

func WithDebug(ctx context.Context, debug bool) context.Context

func WithEditor

func WithEditor(ctx context.Context, isEditor bool) context.Context

func WithPage

func WithPage(ctx context.Context, m *model.Page) context.Context

func WithPageDecorate

func WithPageDecorate(w http.ResponseWriter, value string)

func WithSEO

func WithSEO(ctx context.Context, s seo.SEO) context.Context

func WithSite

func WithSite(ctx context.Context, m *model.Site) context.Context

func WithURL

func WithURL(ctx context.Context, u url.URL) context.Context

Types

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value any, tags ...string) error
	Get(ctx context.Context, key string, value any) error
	DelByKey(ctx context.Context, key string) error
	DelByTag(ctx context.Context, tag string) error
}

type DefaultMatcher

type DefaultMatcher struct {
	// contains filtered or unexported fields
}

func NewDefaultMatcher

func NewDefaultMatcher(voters ...Voter) DefaultMatcher

func (DefaultMatcher) IsAncestor

func (m DefaultMatcher) IsAncestor(ctx context.Context, node *model.Node) bool

func (DefaultMatcher) IsCurrent

func (m DefaultMatcher) IsCurrent(ctx context.Context, node *model.Node) bool

type DefaultMenu

type DefaultMenu struct {
	// contains filtered or unexported fields
}

func NewDefaultMenu

func NewDefaultMenu(menuRepo repository.Menu, nodeRepo repository.Node) *DefaultMenu

func (*DefaultMenu) Get

func (m *DefaultMenu) Get(ctx context.Context, handle string) (model.Menu, error)

type DefaultPageHandler

type DefaultPageHandler struct{}

func NewDefaultPageHandler

func NewDefaultPageHandler() *DefaultPageHandler

func (*DefaultPageHandler) Handle

func (h *DefaultPageHandler) Handle(c echo.Context) error

type DefaultSeeder

type DefaultSeeder struct {
	// contains filtered or unexported fields
}

func NewDefaultSeeder

func NewDefaultSeeder(siteRepository repository.Site, pageRepository repository.Page, logger *zap.Logger) *DefaultSeeder

func (*DefaultSeeder) Boot

func (s *DefaultSeeder) Boot(ctx context.Context) error

func (*DefaultSeeder) CreateErrorPages

func (s *DefaultSeeder) CreateErrorPages(ctx context.Context, site model.Site) error

func (*DefaultSeeder) FindOrCreateLocalhost

func (s *DefaultSeeder) FindOrCreateLocalhost(ctx context.Context) ([]model.Site, error)

func (*DefaultSeeder) InternalCreatePage

func (s *DefaultSeeder) InternalCreatePage(ctx context.Context, site model.Site) error

type DefaultSiteSelector

type DefaultSiteSelector struct {
	// contains filtered or unexported fields
}

func NewDefaultSiteSelector

func NewDefaultSiteSelector(cfgRepository repository.Configuration, siteRepository repository.Site) *DefaultSiteSelector

func (*DefaultSiteSelector) HostByLocaleRetrieve

func (s *DefaultSiteSelector) HostByLocaleRetrieve(r *http.Request, fallbackLocale string) (*model.Site, string, error)

func (*DefaultSiteSelector) HostPathByLocaleRetrieve

func (s *DefaultSiteSelector) HostPathByLocaleRetrieve(r *http.Request, fallbackLocale string) (*model.Site, string, error)

func (*DefaultSiteSelector) HostPathRetrieve

func (s *DefaultSiteSelector) HostPathRetrieve(r *http.Request, fallbackLocale string) (*model.Site, string, error)

func (*DefaultSiteSelector) HostRetrieve

func (s *DefaultSiteSelector) HostRetrieve(r *http.Request, fallbackLocale string) (*model.Site, string, error)

func (*DefaultSiteSelector) Retrieve

func (s *DefaultSiteSelector) Retrieve(r *http.Request) (*model.Site, string, error)

type ErrorHandler

type ErrorHandler struct {
	Logger         *zap.Logger
	Resolver       ErrorResolverFunc
	SiteSelector   SiteSelector
	PageHandler    PageHandler
	PageRepository repository.Page
	CfgRepository  repository.Configuration
}

func NewErrorHandler

func NewErrorHandler(
	pageHandler PageHandler,
	resolver ErrorResolverFunc,
	siteSelector SiteSelector,
	pageRepository repository.Page,
	cfgRepository repository.Configuration,
	logger *zap.Logger,
) *ErrorHandler

func (*ErrorHandler) Handle

func (h *ErrorHandler) Handle(err error, c echo.Context)

type ErrorResolverFunc

type ErrorResolverFunc func(*http.Request, error) (statusCode int, data any)

func ErrorResolver

func ErrorResolver(asHTTPError func(err error, target **echo.HTTPError)) ErrorResolverFunc

type Matcher

type Matcher interface {
	// IsCurrent checks whether a node is current
	IsCurrent(ctx context.Context, node *model.Node) bool

	// IsAncestor checks whether a node is the ancestor of a current node
	IsAncestor(ctx context.Context, node *model.Node) bool
}

Matcher represents an interface for matching nodes. It provides methods for checking whether a node is current or an ancestor.

type Menu interface {
	Get(ctx context.Context, handle string) (model.Menu, error)
}

type PageCreateHandler

type PageCreateHandler struct {
	// contains filtered or unexported fields
}

func NewPageCreateHandler

func NewPageCreateHandler(validator Validator, pageRepo repository.Page) *PageCreateHandler

func (*PageCreateHandler) Handle

func (h *PageCreateHandler) Handle(c echo.Context) error

type PageCreateRequest

type PageCreateRequest struct {
	SiteID   int64  `json:"site_id,omitempty" form:"site_id,omitempty" validate:"required"`
	URL      string `json:"url,omitempty" form:"url,omitempty" validate:"required"`
	Template string `json:"template,omitempty" form:"template,omitempty" validate:"required"`
	Title    string `json:"title,omitempty" form:"title,omitempty" validate:"max=254"`
}

type PageHandler

type PageHandler interface {
	Handle(echo.Context) error
}

type RedirectError

type RedirectError struct {
	Status int
	URL    string
}

func (RedirectError) Error

func (r RedirectError) Error() string

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(theme theme.Theme, cfgRepo repository.Configuration) *Renderer

func (*Renderer) Render

func (renderer *Renderer) Render(w io.Writer, template string, data any, c echo.Context) error

type Seeder

type Seeder interface {
	Boot(context.Context) error
}

type SiteSelector

type SiteSelector interface {
	Retrieve(*http.Request) (m *model.Site, urlPath string, err error)
}

type URLVoter

type URLVoter struct{}

func NewURLVoter

func NewURLVoter() URLVoter

func (URLVoter) MatchNode

func (URLVoter) MatchNode(ctx context.Context, node *model.Node) *bool

type Validator

type Validator interface {
	ValidateCtx(ctx context.Context, obj any) error
}

type Voter

type Voter interface {
	// MatchNode checks whether a node is current.
	//
	// If the voter is not able to determine a result,
	// it should return nil to let other voters do the job.
	MatchNode(ctx context.Context, node *model.Node) *bool
}

Voter represents an interface for determining whether a node is current.

Directories

Path Synopsis
api
v1
fs

Jump to

Keyboard shortcuts

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