catu

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: GPL-3.0 Imports: 36 Imported by: 12

README

Catu

Beware: In development!!!!!!!

Catupiri framework core module

usage

// Start the new app:
app := catu.NewApp()
// Register your plugins
app.RegisterPlugin("mm", mm.GetPlugin())
// Start the bootstrap process, will load all resources, bind routes, middlewares ...
app.Bootstrap()

// here you can use the app resources like run a command or start a server...

// Start the http server if required:
app.StartHTTPServer()

Core events

Powered by: https://github.com/gookit/event

  • configuration
  • bindMiddlewares
  • bindRoutes
  • setResponseFormats
  • bootstrap

Run tests:

go test ./...

Build with

  • Go
  • Time
  • Unknow things that some call magic

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SanitizerDefault *bluemonday.Policy

Functions

func BindMiddlewares added in v0.0.1

func BindMiddlewares(app *App, p *Plugin)

BindMiddlewares - Bind middlewares in order

func CustomHTTPErrorHandler added in v0.0.1

func CustomHTTPErrorHandler(err error, c echo.Context)

func GetConfiguration added in v0.0.1

func GetConfiguration() configuration.Configer

func GetDefaultDatabaseConnection added in v0.0.1

func GetDefaultDatabaseConnection() *gorm.DB

func GetPathLimitFromReq added in v0.0.1

func GetPathLimitFromReq()

func GetQueryInt64FromReq added in v0.0.1

func GetQueryInt64FromReq(param string, c echo.Context) int64

func GetQueryIntFromReq added in v0.0.1

func GetQueryIntFromReq(param string, c echo.Context) int

func GetSanitizer added in v0.0.1

func GetSanitizer() *bluemonday.Policy

func HealthCheckHandler added in v0.0.1

func HealthCheckHandler(c echo.Context) error

func InitSanitizer added in v0.0.1

func InitSanitizer()

Types

type App

type App struct {
	InitTime time.Time

	Events *event.Manager

	Configuration configuration.Configer
	// Default database
	DB *gorm.DB
	// avaible databases
	DBs map[string]*gorm.DB

	Plugins map[string]Pluginer

	Models map[string]interface{}

	Resources map[string]*HTTPResource

	RolesString string
	RolesList   map[string]acl.Role
	// contains filtered or unexported fields
}

func GetApp added in v0.0.1

func GetApp() *App

func Init

func Init() *App

func (*App) Bootstrap added in v0.0.1

func (r *App) Bootstrap() error

func (*App) Can added in v0.0.1

func (r *App) Can(permission string, userRoles []string) bool

func (*App) GetAPIRouterGroup added in v0.0.1

func (r *App) GetAPIRouterGroup(name string) *echo.Group

func (*App) GetModel added in v0.0.1

func (r *App) GetModel(name string) interface{}

func (*App) GetRouter added in v0.0.1

func (r *App) GetRouter() *echo.Echo

func (*App) GetRouterGroup added in v0.0.1

func (r *App) GetRouterGroup(name string) *echo.Group

func (*App) GetTemplates added in v0.0.1

func (r *App) GetTemplates() *template.Template

func (*App) InitDatabase added in v0.0.1

func (r *App) InitDatabase(name, engine string, isDefault bool) error

func (*App) LoadTemplates added in v0.0.1

func (r *App) LoadTemplates() error

func (*App) RegisterPlugin added in v0.0.1

func (r *App) RegisterPlugin(p Pluginer)

func (*App) SetAPIRouterGroup added in v0.0.1

func (r *App) SetAPIRouterGroup(name, path string) *echo.Group

func (*App) SetModel added in v0.0.1

func (r *App) SetModel(name string, f interface{})

func (*App) SetResource added in v0.0.6

func (r *App) SetResource(name string, httpController HTTPController, routerGroup *echo.Group) error

Set Resource CRUD. Now we only supports HTTP Resources / Ex Rest

func (*App) SetRouterGroup added in v0.0.1

func (r *App) SetRouterGroup(name, path string) *echo.Group

func (*App) SetTemplateFunction added in v0.0.1

func (r *App) SetTemplateFunction(name string, f interface{})

func (*App) StartHTTPServer added in v0.0.1

func (r *App) StartHTTPServer() error

type BaseErrorResponse added in v0.0.1

type BaseErrorResponse struct {
	Messages []BaseErrorResponseMessage `json:"messages"`
}

type BaseErrorResponseMessage added in v0.0.1

type BaseErrorResponseMessage struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

type BaseListReponse added in v0.0.1

type BaseListReponse struct {
	Meta BaseMetaResponse `json:"meta"`
}

type BaseMetaResponse added in v0.0.1

type BaseMetaResponse struct {
	Count int64 `json:"count"`
}

type ContentDates added in v0.0.1

type ContentDates interface {
	GetTeaserDatesHTML(separator string) template.HTML
}

type CustomBinder added in v0.0.3

type CustomBinder struct{}

func (*CustomBinder) Bind added in v0.0.3

func (cb *CustomBinder) Bind(i interface{}, c echo.Context) (err error)

type HTMLMetaTags

type HTMLMetaTags struct {
	Title       string
	Description string
	Canonical   string
	SiteName    string
	Type        string
	ImageURL    string
	Keywords    string

	TwitterSite string
}

type HTTPController added in v0.0.6

type HTTPController interface {
	Query(c echo.Context) error
	Create(c echo.Context) error
	Count(c echo.Context) error
	FindOne(c echo.Context) error
	Update(c echo.Context) error
	Delete(c echo.Context) error
}

type HTTPError added in v0.0.4

type HTTPError struct {
	Code    int         `json:"code"`
	Message interface{} `json:"message"`
}

type HTTPResource added in v0.0.6

type HTTPResource struct {
	Name       string
	Controller *HTTPController
}

type Plugin added in v0.0.1

type Plugin struct {
	Name string
}

func (*Plugin) BindMiddlewares added in v0.0.1

func (p *Plugin) BindMiddlewares(a *App) error

func (*Plugin) GetName added in v0.0.1

func (p *Plugin) GetName() string

func (*Plugin) Init added in v0.0.1

func (p *Plugin) Init(a *App) error

func (*Plugin) SetTemplateFuncMap added in v0.0.1

func (p *Plugin) SetTemplateFuncMap(app *App) error

type PluginManager added in v0.0.1

type PluginManager interface {
	GetRouter(name string) *echo.Group
	SetRouter(name string) *echo.Group
	GetAPIRouter(name string) *echo.Group
}

type Pluginer added in v0.0.1

type Pluginer interface {
	Init(app *App) error
	GetName() string
}

type RequestContext added in v0.0.6

type RequestContext struct {
	PathBeforeAlias string
	Protocol        string
	Domain          string
	AppOrigin       string
	Title           string

	IsAuthenticated   bool
	AuthenticatedUser UserInterface
	// authenticated user role name list
	Roles []string

	Session SessionData

	// Widgets     map[string]map[string]string
	Layout              string
	BodyClass           []string
	Content             template.HTML
	ContentData         map[string]interface{}
	Query               query_parser_to_db.QueryInterface
	Pager               *pagination.Pager
	MetaTags            HTMLMetaTags
	ResponseContentType string

	ENV string
}

func NewRequestContext added in v0.0.6

func NewRequestContext() RequestContext

func NewRequestRequestContext added in v0.0.6

func NewRequestRequestContext(c echo.Context) RequestContext

func (*RequestContext) AddBodyClass added in v0.0.6

func (r *RequestContext) AddBodyClass(class string)

Add a body class string checking if is unique

func (*RequestContext) Can added in v0.0.6

func (r *RequestContext) Can(permission string) bool

func (*RequestContext) Get added in v0.0.6

func (r *RequestContext) Get(name string) interface{}

func (*RequestContext) GetAuthenticatedRoles added in v0.0.6

func (r *RequestContext) GetAuthenticatedRoles() *[]string

func (*RequestContext) GetBodyClassText added in v0.0.6

func (r *RequestContext) GetBodyClassText() string

Get body class as string,

func (*RequestContext) GetBool added in v0.0.6

func (r *RequestContext) GetBool(name string) bool

func (*RequestContext) GetLimit added in v0.0.6

func (r *RequestContext) GetLimit() int

func (*RequestContext) GetOffset added in v0.0.6

func (r *RequestContext) GetOffset() int

func (*RequestContext) GetString added in v0.0.6

func (r *RequestContext) GetString(name string) string

func (*RequestContext) GetStringMap added in v0.0.6

func (r *RequestContext) GetStringMap(name string) []string

func (*RequestContext) GetTemplateHTML added in v0.0.6

func (r *RequestContext) GetTemplateHTML(name string) template.HTML

func (*RequestContext) ParseQueryFromReq added in v0.0.6

func (r *RequestContext) ParseQueryFromReq(c echo.Context) error

func (*RequestContext) RemoveBodyClass added in v0.0.6

func (r *RequestContext) RemoveBodyClass(class string)

Remove a body class string checking if is unique

func (*RequestContext) Render added in v0.0.6

func (r *RequestContext) Render(wr io.Writer, name string, data interface{}) error

Render one template, alias to app.templates.ExecuteTemplate()

func (*RequestContext) RenderMetaTags added in v0.0.6

func (r *RequestContext) RenderMetaTags() template.HTML

func (*RequestContext) RenderPagination added in v0.0.6

func (r *RequestContext) RenderPagination(name string) string

func (*RequestContext) Set added in v0.0.6

func (r *RequestContext) Set(name string, value interface{})

func (*RequestContext) SetAuthenticatedUser added in v0.0.6

func (r *RequestContext) SetAuthenticatedUser(user UserInterface)

func (*RequestContext) SetAuthenticatedUserAndFillRoles added in v0.0.6

func (r *RequestContext) SetAuthenticatedUserAndFillRoles(user UserInterface)

type SessionData added in v0.0.1

type SessionData struct {
	UserID string
}

type TemplateCTX added in v0.0.1

type TemplateCTX struct {
	EchoContext echo.Context
	Ctx         interface{}
	Record      interface{}
	Records     interface{}
}

type TemplateRenderer added in v0.0.1

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

func (*TemplateRenderer) Render added in v0.0.1

func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

type UserInterface added in v0.0.1

type UserInterface interface {
	// getters:
	GetID() string
	SetID(id string) error
	GetRoles() []string
	SetRoles(v []string) error
	AddRole(role string) error
	RemoveRole(role string) error
	GetEmail() string
	SetEmail(v string) error
	GetUsername() string
	SetUsername(v string) error
	GetDisplayName() string
	SetDisplayName(v string) error
	GetFullName() string
	SetFullName(v string) error
	GetLanguage() string
	SetLanguage(v string) error
	IsActive() bool
	SetActive(blocked bool) error
	IsBlocked() bool
	SetBlocked(blocked bool) error
	// FillById
	FillById(ID string) error
}

type ValidationFieldError added in v0.0.3

type ValidationFieldError struct {
	Field   string `json:"field"`
	Tag     string `json:"tag"`
	Value   string `json:"value"`
	Message string `json:"message"`
}

type ValidationResponse added in v0.0.3

type ValidationResponse struct {
	Errors []*ValidationFieldError `json:"errors"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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