cms

package module
v0.1.1 Latest Latest
Warning

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

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

README

CMS

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

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

This section is empty.

Variables

View Source
var ErrInternal = errors.New("internal server error")

Functions

func APIAuthorizer added in v0.0.9

func APIAuthorizer(authorizer echox.Authorizer) api.Authorizer

func Authorizer added in v0.0.9

func Authorizer(authorizer rbac.Authorizer) echox.Authorizer

func BasicAuthValidator

func BasicAuthValidator(repo repository.Admin, logger *zap.Logger) middleware.BasicAuthValidator

func BuildTree

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

func CtxAdmin

func CtxAdmin(ctx context.Context) *model.Admin

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 CtxTwoFA

func CtxTwoFA(ctx context.Context) bool

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 IsTLS

func IsTLS(r *http.Request) bool

func IsTextHTML

func IsTextHTML(header http.Header) bool

func JWTAuthValidator

func JWTAuthValidator(repo repository.Admin, secret string) middleware.KeyAuthValidator

func Languages

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

func MediaType

func MediaType(header http.Header) string

func NewJWT

func NewJWT(payload jwt.MapClaims, signingKey string, exp time.Duration) (string, error)

NewJWT generates and returns new HS256 signed JWT.

func PageDecorate

func PageDecorate(w http.ResponseWriter) bool

func PageNotDecorate

func PageNotDecorate(w http.ResponseWriter) bool

func ParseJWT

func ParseJWT(token string, verificationKey string) (jwt.MapClaims, error)

ParseJWT verifies and parses JWT and returns its claims.

func ParseUnverifiedJWT

func ParseUnverifiedJWT(token string) (jwt.MapClaims, error)

ParseUnverifiedJWT parses JWT and returns its claims but DOES NOT verify the signature.

It verifies only the exp, iat and nbf claims.

func RandomString

func RandomString(length int) string

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 WithAdmin

func WithAdmin(ctx context.Context, admin *model.Admin) context.Context

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 WithTwoFA

func WithTwoFA(ctx context.Context, twoFA bool) context.Context

func WithURL

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

Types

type AdminService

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

func NewAdminService

func NewAdminService(repo repository.Admin) *AdminService

func (*AdminService) ChangePassword

func (s *AdminService) ChangePassword(ctx context.Context, email, password string) error

func (*AdminService) ChangeRoles

func (s *AdminService) ChangeRoles(ctx context.Context, email string, roles ...string) error

func (*AdminService) Create

func (s *AdminService) Create(ctx context.Context, email, password, issuer string, roles ...string) (model.Admin, string, error)

func (*AdminService) GetOTPKey

func (s *AdminService) GetOTPKey(ctx context.Context, email, issuer string, newOTP bool) (string, error)

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 TwoFAAssertion

type TwoFAAssertion struct{}

func (TwoFAAssertion) Assert

func (TwoFAAssertion) Assert(ctx context.Context, _ rbac.Role, _ string) (bool, 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