lazycontroller

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRequest = &Error{Code: 400}
View Source
var (
	ErrBodyAlreadySent error = fmt.Errorf("body already sent")
)
View Source
var ErrForbidden = &Error{Code: 403}
View Source
var ErrNotFound = &Error{Code: 404}
View Source
var ErrUnauthorized = &Error{Code: 401}
View Source
var ErrUnprocessableEntity = &Error{Code: 422}
View Source
var FlashError = "error" // Red
View Source
var FlashNotice = "notice" // Blue
View Source
var FlashSuccess = "success" // Green
View Source
var FlashWarning = "warning" // Yellow
View Source
var MaxFormSize int64 = 10 * 1024 * 1024
View Source
var SessionName = "lazy_session"
View Source
var Store = sessions.NewCookieStore([]byte("Tjz@-QNkekP2KH8oF9A_GNssbwvftXqv"))

Functions

This section is empty.

Types

type Accepts

type Accepts map[MimeType]MimeTypeParams

type Controller

type Controller struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter

	ControllerName string
	ActionName     string
	Namespace      string

	ViewVariables []any

	Layout string
	W      http.ResponseWriter
	// contains filtered or unexported fields
}

func (*Controller) Accepts

func (c *Controller) Accepts() Accepts

func (*Controller) AddErrorFlash

func (c *Controller) AddErrorFlash(msg any)

func (*Controller) AddFlash

func (c *Controller) AddFlash(key string, value any)

func (*Controller) AddNoticeFlash

func (c *Controller) AddNoticeFlash(msg any)

func (*Controller) AddSuccessFlash

func (c *Controller) AddSuccessFlash(msg any)

func (*Controller) AddWarningFlash

func (c *Controller) AddWarningFlash(msg any)

func (*Controller) After_ZZZZ_EnsureRender

func (c *Controller) After_ZZZZ_EnsureRender()

func (*Controller) BadRequest

func (c *Controller) BadRequest()

func (*Controller) Before_0000_SetupRequest

func (c *Controller) Before_0000_SetupRequest(r *http.Request, w http.ResponseWriter, a *lazyassets.Storage, route *lazydispatch.Route, dispatcher *lazydispatch.Dispatcher, views *lazyview.Views)

func (*Controller) CSRFToken

func (c *Controller) CSRFToken() string

func (*Controller) FillWithParams

func (c *Controller) FillWithParams(model string, data any) error

func (*Controller) Flashes

func (c *Controller) Flashes(key ...string) []FlashMessager

func (*Controller) FlashesByType

func (c *Controller) FlashesByType() map[string][]any

func (*Controller) Forbidden

func (c *Controller) Forbidden()

func (*Controller) Gen_Params

func (c *Controller) Gen_Params() *Params

func (*Controller) HandleError

func (c *Controller) HandleError(err error)

func (*Controller) HeaderSet

func (c *Controller) HeaderSet(key string, value string)

func (*Controller) NoContent

func (c *Controller) NoContent()

func (*Controller) ParamsGet

func (c *Controller) ParamsGet(name string) string

func (*Controller) ParamsGetBool

func (c *Controller) ParamsGetBool(name string) bool

func (*Controller) ParamsGetInt

func (c *Controller) ParamsGetInt(name string) int

func (*Controller) ParamsGetUint

func (c *Controller) ParamsGetUint(name string) uint

func (*Controller) ParamsIsPresent

func (c *Controller) ParamsIsPresent(name string) bool

func (*Controller) PathTo

func (c *Controller) PathTo(args ...any) string

func (*Controller) Redirect

func (c *Controller) Redirect(url string, code ...int)

func (*Controller) RedirectBack

func (c *Controller) RedirectBack(fallback string, code ...int)

func (*Controller) RedirectTo

func (c *Controller) RedirectTo(args ...any)

func (*Controller) Render

func (c *Controller) Render()

func (*Controller) RenderContent

func (c *Controller) RenderContent(content string)

func (*Controller) SendFile

func (c *Controller) SendFile(filename string, data io.Reader)

func (*Controller) SessionDelete

func (c *Controller) SessionDelete(key string)

func (*Controller) SessionGet

func (c *Controller) SessionGet(key string) *lazysupport.Value

func (*Controller) SessionSet

func (c *Controller) SessionSet(key string, value any)

func (*Controller) SessionValues

func (c *Controller) SessionValues() map[any]any

SessionValues return all values in the session. Modifying the returned map may or may not work. Use SessionSet or SessionDelete instead.

func (*Controller) TurboStream

func (c *Controller) TurboStream(streams ...io.WriterTo)

func (*Controller) URLParam

func (c *Controller) URLParam(s string) (string, bool)

func (*Controller) URLParamInt

func (c *Controller) URLParamInt(s string) (int, bool)

func (*Controller) URLParamUint

func (c *Controller) URLParamUint(s string) (uint, bool)

func (*Controller) UnprocessableEntity

func (c *Controller) UnprocessableEntity()

func (*Controller) ViewData

func (v *Controller) ViewData(val any)

func (*Controller) ViewObj

func (v *Controller) ViewObj(val any)

func (*Controller) ViewVar

func (v *Controller) ViewVar(name string, val any)

func (*Controller) Wants

func (c *Controller) Wants(mimes ...string) bool

func (*Controller) WantsHTML

func (c *Controller) WantsHTML() bool

func (*Controller) WantsJSON

func (c *Controller) WantsJSON() bool

func (*Controller) WantsTurbo

func (c *Controller) WantsTurbo() bool

func (*Controller) WithParam

func (c *Controller) WithParam(name string, fn func(string))

func (*Controller) WithParamBool

func (c *Controller) WithParamBool(name string, fn func(bool))

func (*Controller) WithParamInt

func (c *Controller) WithParamInt(name string, fn func(int))

func (*Controller) WithParamUint

func (c *Controller) WithParamUint(name string, fn func(uint))

type ErrOpts

type ErrOpts struct {
	Err        error
	Message    string
	Title      string
	Location   string
	Code       int
	Offset     int
	Stacktrace bool
	Format     string
	FormatArgs []any
}

type Error

type Error struct {

	// Location is the destination of the error
	// If set, lazydispatch will:
	// * Set the Location header
	// * Default the http status code to 302
	// * Set error.Error() as a flash message
	Location string

	// Code is the http status code to return
	Code int

	// Raise is a flag to raise the error as exception after sending the resposne to the client
	Raise bool

	// Public is a flag to indicate if the error is public
	// If set, the user will see the details of the error message
	// Otherwise, the user will see a generic error message
	// NOTE: This only applies to environments that are not development or tests
	Public bool

	// NoFlash ensure that a flash is not generated to the user
	NoFlash bool

	ErrTitle   string
	ErrMessage string
	// contains filtered or unexported fields
}

Error represents a generic error

func NewError

func NewError(opts ErrOpts) *Error

func NewErrorf

func NewErrorf(offset int, format string, data ...any) *Error

func NewRedirectError

func NewRedirectError(offset int, location string, err error) *Error

func NewRedirectErrorf

func NewRedirectErrorf(offset int, location string, format string, data ...any) *Error
func NewError(offset int, err error) *Error {
	return &Error{
		error: lazysupport.NewError(offset+1, err),
	}
}

func (Error) Message

func (e Error) Message() string

func (Error) String

func (e Error) String() string

func (Error) Title

func (e Error) Title() string

func (Error) Unwrap

func (e Error) Unwrap() error

type ErrorWithHandler

type ErrorWithHandler interface {
	Handler() http.Handler
}

type File

type File struct {
	Name        string
	ContentType string
	Size        int64
	multipart.File
}

type Flash

type Flash string

func (Flash) Message

func (s Flash) Message() string

func (Flash) Title

func (s Flash) Title() string

type FlashMessage

type FlashMessage struct {
	T string
	M string
}

func (FlashMessage) Message

func (f FlashMessage) Message() string

func (FlashMessage) Title

func (f FlashMessage) Title() string

type FlashMessager

type FlashMessager interface {
	Title() string
	Message() string
}

type MimeType

type MimeType string

type MimeTypeParams

type MimeTypeParams map[string]string

type Params

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

func (*Params) File

func (p *Params) File(name string) *File

func (*Params) Get

func (p *Params) Get(name string) string

func (*Params) GetBool

func (p *Params) GetBool(name string) (value bool, ok bool)

func (*Params) GetInt

func (p *Params) GetInt(name string) int

func (*Params) GetString

func (p *Params) GetString(name string) string

GetString is similar to get but it strips tags and remove spaces

func (*Params) GetUint

func (p *Params) GetUint(name string) uint

func (*Params) IsPresent

func (p *Params) IsPresent(name string) bool

func (*Params) With

func (p *Params) With(name string, fn func(string))

func (*Params) WithFile

func (p *Params) WithFile(name string, fn func(*File))

type RedirectError

type RedirectError struct {
	Location string
	Code     int
}

func (*RedirectError) Error

func (e *RedirectError) Error() string

func (*RedirectError) ServeHTTP

func (e *RedirectError) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Session

type Session Controller

type TemplateObj

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

func Obj

func Obj(value any) TemplateObj

type TemplateVar

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

func Var

func Var(key string, value any) TemplateVar

Jump to

Keyboard shortcuts

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