cp

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 64 Imported by: 0

README

Creampuff

Documentation

Index

Constants

View Source
const (
	FlashMessageTypeSuccess = "success"
	FlashMessageTypeWarning = "warning"
	FlashMessageTypeError   = "error"
)
View Source
const (
	UserActive       = "active"
	UserRoles        = "roles"
	UserEmail        = "email"
	UserPassword     = "password"
	UserTfa          = "tfa"
	UserTfaSecret    = "tfa_secret"
	UserTfaCodes     = "tfa_codes"
	UserTfaUrl       = "tfa_url"
	UserLastActivity = "last_activity"
)

Variables

View Source
var (
	ErrorInvalidCredentials = errors.New("invalid credentials")
	ErrorInvalidDatabase    = errors.New("invalid database")
	ErrorForbidden          = errors.New("insufficient rights")
)
View Source
var (
	ErrorMissingUser      = errors.New("user doesn't exist")
	ErrorMismatchPassword = errors.New("passwords aren't equal")
	ErrorHash             = errors.New("hash failed")
)
View Source
var (
	FlashMessageExpiration = time.Hour
)

Functions

func Connect

func Connect(path ...route.PathValue) route.Config

func CreateMigrationsConnections

func CreateMigrationsConnections(config config.Databases) map[string]*quirk.DB

func CreateUsersTable added in v0.1.3

func CreateUsersTable(q *quirk.Quirk, customFields ...quirk.Field)

func Delete

func Delete(path ...route.PathValue) route.Config

func DropUsersTable added in v0.1.3

func DropUsersTable(q *quirk.Quirk)

func Get

func Get(path ...route.PathValue) route.Config

func Handler

func Handler(fn handler.Fn) route.Config
func Head(path ...route.PathValue) route.Config

func Interface

func Interface[T any]() string

func IsFirstCharUpper

func IsFirstCharUpper(v string) bool

func Layout

func Layout(name string) route.Config

func Localize

func Localize() route.Config

func Method

func Method(methods ...route.Config) route.Config

func Name

func Name(name string) route.Config

func Options

func Options(path ...route.PathValue) route.Config

func Patch

func Patch(path ...route.PathValue) route.Config

func Path

func Path(path route.PathValue) route.Config

func Post

func Post(path ...route.PathValue) route.Config

func Provide

func Provide[T any](c Control, name ...string) *T

func Put

func Put(path ...route.PathValue) route.Config

func Query

func Query[T any](c Control, key string) T

func Route

func Route(configs ...route.Config) *route.Builder

func Trace

func Trace(path ...route.PathValue) route.Config

func Var

func Var[T any](c Control, key string) T

Types

type AddFlashMessage added in v0.1.4

type AddFlashMessage interface {
	Success(title string, subtitle ...string)
	Warning(title string, subtitle ...string)
	Error(title string, subtitle ...string)
}

type Auth

type Auth interface {
	Session() SessionManager
	Tfa() TfaManager
	User(dbname ...string) UserManager
	CustomUser(id int, email string, dbname ...string) UserManager

	In(email, password string) AuthIn
	Out()
}

type AuthIn

type AuthIn interface {
	Token() string
	Ok() bool
	Tfa() bool
	Error() error
}

type Cache

type Cache interface {
	Exists(key string) bool
	Get(key string, data any)
	Set(key string, data any, expiration time.Duration)
	Destroy(key string)
}

type Component

type Component interface {
	Control
	Main() Control
}

type Control

type Control interface {
	Assets() assets.Assets
	Auth() Auth
	Cache() Cache
	Continue() Result
	Cookie() Cookie
	Config() config.Config
	Create() Create
	Csrf() Csrf
	DB(name ...string) *quirk.Quirk
	Dev() dev.Dev
	Email() Email
	Error() ErrorHandler
	File() filesystem.Filesystem
	Flash() FlashMessenger
	Generate() Generator
	Link(name string, arg ...Map) string
	Page() page.Page
	Request() Request
	Response() Response
	State() StateManager
	Translate(key string, args ...map[string]any) string
}

type Controller

type Controller interface {
	Name() string
	Routes() Routes
}

type Controllers

type Controllers []Controller
type Cookie interface {
	Get(name string) string
	Set(name string, value any, expiration time.Duration)
	Destroy(name string)
}

type Core

type Core interface {
	Container(dependencies ...*Dependency) Core
	Controllers(controllers ...Controller) Core
	Form() Form
	Middleware(middlewares ...handler.Fn) Core
	Modules(modules ...Module) Core
	Routes(builders ...*route.Builder) Core
	Serve()
	Ui() Ui
}

func New

func New(configDir string) Core

type Create

type Create interface {
	Component(component component) gox.Node
	Defer(link string, nodes ...gox.Node) gox.Node
	FormBuilder(fields ...*form.FieldBuilder) *form.Builder
}

type Csrf

type Csrf interface {
	Get(token, name string) Token
	Create(key, name, ip, userAgent string) string
	Destroy(token string)
	Clean()
}

type Dependency

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

func Register

func Register(provider Provider) *Dependency

func (*Dependency) Name

func (d *Dependency) Name(name string) *Dependency

func (*Dependency) Singleton

func (d *Dependency) Singleton() *Dependency

type Email

type Email interface {
	Attachment(name string, data []byte) Email
	Body(nodes ...gox.Node) Email
	Bytes() []byte
	Copy(values ...string) Email
	From(from string) Email
	HiddenCopy(values ...string) Email
	Subject(subject string) Email
	Title(title string) Email
	To(to ...string) Email
	Send()
	String() string
}

type Error

type Error struct {
	Message    string
	Route      string
	StatusCode int
}

type ErrorHandler

type ErrorHandler interface {
	Check(err error)
	Throw()
	Message(message string, params ...map[string]any) ErrorHandler
	Internal() ErrorHandler
	BadRequest() ErrorHandler
	Forbidden() ErrorHandler
	Unauthorized() ErrorHandler
	NotFound() ErrorHandler
}

type FlashMessage added in v0.1.4

type FlashMessage struct {
	Type     string `json:"type"`
	Title    string `json:"title"`
	Subtitle string `json:"subtitle"`
}

type FlashMessenger added in v0.1.4

type FlashMessenger interface {
	Get() []FlashMessage
	Add() AddFlashMessage
}

type Form added in v0.1.8

type Form interface {
	Errors(errors map[string]string) Form
}

type Generator

type Generator interface {
	Hx() HxGenerator
	Link() LinkGenerator
	Query(arg Map) string
	Url() UrlGenerator
}

type HxGenerator added in v0.2.4

type HxGenerator interface {
	Csrf(key, name string) gox.Node
}

type LinkGenerator

type LinkGenerator interface {
	Action(action string, arg ...Map) string
	Name(name string, arg ...Map) string
	SwitchLang(langCode string, overwrite ...Map) string
}

type Map

type Map = map[string]any

type Module

type Module interface {
	Controllers() Controllers
	Name() string
}

type Provider

type Provider interface {
	Provide(control Control) Provider
}

type Request

type Request interface {
	ContentType() string
	Form() requester.Form
	Header() http.Header
	Host() string
	Ip() string
	Is() requester.Is
	Lang() string
	Method() string
	Path() string
	Protocol() string
	Query(key string, defaultValue ...string) string
	Raw() *http.Request
	Route() string
	UserAgent() string
	Var(key string, defaultValue ...string) string
}

type Response

type Response interface {
	Error(err error) Result
	File(name string, data []byte) Result
	Json(value any) Result
	Header() http.Header
	Hx() hx.Response
	Raw() http.ResponseWriter
	Redirect(name string, arg ...Map) Result
	Refresh() Result
	Render(nodes ...gox.Node) Result
	Status(statusCode int) Response
	Text(text string) Result
	Empty() Result
}

type Result

type Result interface{}

type Routes

type Routes []*route.Builder

type SessionManager

type SessionManager interface {
	Exists() bool
	Get() session.Session
	New(user User) string
	Renew()
	Destroy()
}

type StateManager

type StateManager interface {
	Exists() bool
	Get(result any)
	Set(data any)
	Reset()
}

type TfaManager

type TfaManager interface {
	GetPendingUserId() int
	PendingVerification() bool
	Active() bool
	Enable(id ...int)
	Disable(id ...int)
	Verify(otp string) (string, bool)
	CreateQrImage(nodes ...gox.Node) gox.Node
}

type Token

type Token struct {
	Exist     bool   `json:"exist"`
	Name      string `json:"name"`
	Ip        string `json:"ip "`
	UserAgent string `json:"userAgent"`
	Token     string `json:"token"`
}

type Ui

type Ui interface {
	ErrorPage(fn uiErrorFn) Ui
	Flash(fn uiFlashFn) Ui
	Layout(name string, fn uiLayoutFn) Ui
}

type UrlGenerator

type UrlGenerator interface {
	Asset(path string) string
}

type User

type User struct {
	Id           int            `json:"id"`
	Active       bool           `json:"active"`
	Roles        []string       `json:"roles"`
	Email        string         `json:"email"`
	Password     string         `json:"password"`
	Tfa          bool           `json:"tfa"`
	TfaSecret    sql.NullString `json:"tfaSecret"`
	TfaCodes     sql.NullString `json:"tfaCodes"`
	TfaUrl       sql.NullString `json:"tfaUrl"`
	LastActivity time.Time      `json:"lastActivity"`
	CreatedAt    time.Time      `json:"createdAt"`
	UpdatedAt    time.Time      `json:"updatedAt"`
	// contains filtered or unexported fields
}

type UserField

type UserField struct {
	Name  string
	Value any
}

type UserManager

type UserManager interface {
	Get(id ...int) User
	Create(r User) int
	Update(r User, columns ...string)
	UpdatePassword(actualPassword, newPassword string) error
	ForceUpdatePassword(newPassword string) error
	Enable(id ...int)
	Disable(id ...int)
}

func CreateUserManager

func CreateUserManager(db *quirk.DB, id int, email string) UserManager

Jump to

Keyboard shortcuts

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