sense

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangCookieKey = "X-Lang"
)
View Source
const (
	Main = "main"
)

Variables

View Source
var (
	ErrorInvalidDatabase  = errors.New("invalid database")
	ErrorInvalidWebsocket = errors.New("invalid websocket")
	ErrorInvalidLang      = errors.New("invalid lang")
	ErrorInvalidMultipart = errors.New("request has not multipart content type")
	ErrorOpenFile         = errors.New("file cannot be opened")
	ErrorReadData         = errors.New("cannot read data")
)
View Source
var (
	BlueColor    = lipgloss.NewStyle().Foreground(lipgloss.Color("#60a5fa"))
	EmeraldColor = lipgloss.NewStyle().Foreground(lipgloss.Color("#34d399"))
	WhiteColor   = lipgloss.NewStyle().Foreground(lipgloss.Color("#ffffff"))
)
View Source
var (
	Divider = WhiteColor.Render("------------------------------")
)

Functions

func PathValue

func PathValue[T Assert](c RequestContext, key string, defaultValue ...T) T

func Query

func Query[T Assert](c RequestContext, key string, defaultValue ...T) T

Types

type Assert

type Assert interface {
	string | int | float32 | float64 | bool
}

type Config

type Config struct {
	App          config.App
	Cache        config.Cache
	Database     map[string]*quirk.DB
	Filesystem   filesystem.Config
	Localization config.Localization
	Parser       config.Parser
	Router       config.Router
	Security     config.Security
	Smtp         mailer.Config
}

type Context

type Context interface {
	Auth(dbname ...string) auth.Manager
	Cache() cache.Client
	Cookie() cookie.Cookie
	Config() Config
	Continue() error
	Db(dbname ...string) *quirk.Quirk
	Email() mailer.Mailer
	Files() filesystem.Client
	Lang() LangContext
	Parse() ParseContext
	Request() RequestContext
	Send() SendContext
	Translate(key string, args ...map[string]any) string
	Validate(s validator.Schema, data any) (bool, ErrorsWrapper[validator.Errors])
}

type ErrorsWrapper added in v0.1.2

type ErrorsWrapper[T any] struct {
	Errors T `json:"errors"`
}

type Handler

type Handler func(c Context) error

type Hook

type Hook interface {
	OnError(fn func(req RequestContext, err error)) Hook
}

type Interceptor

type Interceptor interface {
	OnJson(fn func(req RequestContext, json any) any) Interceptor
	OnBool(fn func(req RequestContext, value bool) bool) Interceptor
	OnXml(fn func(req RequestContext, xml any) any) Interceptor
	OnText(fn func(req RequestContext, text string) string) Interceptor
	OnError(fn func(req RequestContext, err error) error) Interceptor
}

type LangContext

type LangContext interface {
	Exists() bool
	Get() string
}

type ParseContext

type ParseContext interface {
	File(filename string) (form.Multipart, error)
	Files(filesname ...string) ([]form.Multipart, error)
	Json(target any) error
	Text() (string, error)
	Xml(target any) error
}

type RequestContext

type RequestContext interface {
	ContentType() string
	Header() http.Header
	Host() string
	Ip() string
	Is() RequestIsContext
	Method() string
	Path() string
	Protocol() string
	Raw() *http.Request
	UserAgent() string
}

type RequestIsContext

type RequestIsContext interface {
	Get() bool
	Post() bool
	Put() bool
	Patch() bool
	Delete() bool
}

type Route

type Route struct {
	Method    string
	Path      string
	Firewalls []config.Firewall
}

type Router

type Router interface {
	Hook() Hook
	Intercept() Interceptor
	Static(path, dir string) Router
	Use(handler Handler) Router
	Group(pathPrefix string) Router
	Get(path string, handler Handler)
	Post(path string, handler Handler)
	Put(path string, handler Handler)
	Patch(path string, handler Handler)
	Delete(path string, handler Handler)
	Ws(path, name string, handler Handler)
}

type SendContext

type SendContext interface {
	Header() http.Header
	Status(statusCode int) SendContext
	Error(err any) error
	Text(value string) error
	Bool(value bool) error
	Json(value any) error
	Xml(value any) error
	Redirect(url string) error
	File(name string, bytes []byte) error
	Ws(name string) WsWriter
}

type Sense

type Sense interface {
	Router
	Run(address string)
}

func New

func New(config Config) Sense

type WsWriter

type WsWriter interface {
	Id(id ...int) WsWriter
	Session() WsWriter
	Json(value any) error
	Text(value string) error
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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