mirage

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT, MIT Imports: 41 Imported by: 18

Documentation

Index

Constants

View Source
const (
	FlashSuccess = "success"
	FlashWarning = "warning"
	FlashError   = "error"
)
View Source
const (
	Action = "action"
	Main   = "main"
)
View Source
const (
	Version = "0.1.9"
)

Variables

View Source
var (
	ErrorInvalidDatabase = errors.New("invalid database")
	ErrorNoPtr           = errors.New("target is not a pointer")
	ErrorMismatchType    = errors.New("target is not equal with value type")
)

Functions

func TestRoute

func TestRoute(param TestRouteParam) *httptest.ResponseRecorder

Types

type Component

type Component struct {
	Ctx `json:"-"`
}

type Ctx

type Ctx interface {
	Auth(dbname ...string) auth.Manager
	Cache() cache.Client
	Config() config.Config
	Continue() error
	Cookie() cookie.Cookie
	Create() Factory
	Csrf() csrf.Csrf
	DB(dbname ...string) *quirk.DB
	Email() mailer.Mailer
	Export() Export
	Files() filesystem.Client
	Flash() Flash
	Generate() Generator
	Lang() Lang
	Page() Page
	Parse() parser.Parse
	Request() Request
	Response() Response
	State() State
	Translate(key string, args ...map[string]any) string
}

func TestCtx

func TestCtx(param TestCtxParam) Ctx

type Export

type Export interface {
	Csv() exporter.Csv
	Excel() exporter.Excel
	Pdf() exporter.Pdf
}

type Factory

type Factory interface {
	Component(ct MandatoryComponent) gox.Node
	Defer(link string, nodes ...gox.Node) gox.Node
	Form(fields ...*form.FieldBuilder) *form.Builder
}

type Flash

type Flash interface {
	Get() ([]Message, error)
	Success(title, value string) error
	Warning(title, value string) error
	Error(title, value string) error

	MustGet() []Message
	MustSuccess(title, value string)
	MustWarning(title, value string)
	MustError(title, value string)
}

type Generator

type Generator interface {
	Assets() gox.Node
	Action(name string, args ...Map) string
	Current(qpm ...Map) string
	Csrf(name string) gox.Node
	Link(name string, args ...Map) string
	PublicUrl(path string) string
	Query(args Map) string
	SwitchLang(langCode string) string
}

type Handler

type Handler func(c Ctx) error

type Intercept

type Intercept interface {
	Error() error
	Status() int
}

type Lang

type Lang interface {
	Main() string
	Exists() bool
	Current() string
}

type LayoutManager

type LayoutManager interface {
	Add(name string, layout layoutFactory) LayoutManager
}

type MandatoryComponent

type MandatoryComponent interface {
	gox.Node
	Name() string
	Mount()
}

type Map

type Map map[string]any

func (Map) Merge

func (m Map) Merge(mm Map) Map

type Message

type Message struct {
	Type  string `json:"type"`
	Title string `json:"title"`
	Value string `json:"value"`
}

type Mirage

type Mirage interface {
	Router
	DynamicHandler(handler Handler) Mirage
	Layout() LayoutManager
	Run(address string)
	Mux() *http.ServeMux
	Plugin(plugin Plugin) Mirage
}

func New

func New(cfg config.Config) Mirage

type Page

type Page interface {
	Get() PageGetter
	Set() PageSetter
}

type PageGetter

type PageGetter interface {
	Title() string
	Description() string
	Keywords() string
	Metas() [][2]string
}

type PageSetter

type PageSetter interface {
	Title(title string) PageSetter
	Description(description string) PageSetter
	Keywords(keywords ...string) PageSetter
	Meta(name, content string) PageSetter
}

type Plugin

type Plugin struct {
	Name    string
	Locales map[string]map[string]string
}

type Request

type Request interface {
	Action() string
	ContentType() string
	Form() url.Values
	Header() http.Header
	Host() string
	Ip() string
	Is() RequestIs
	Method() string
	Name() string
	Origin() string
	Parsed() Map
	Path() string
	PathValue(key string, defaultValue ...string) string
	QueryParam(key string, defaultValue ...string) string
	QueryMap() Map
	Protocol() string
	Raw() *http.Request
	UserAgent() string
}

type RequestIs

type RequestIs interface {
	Get() bool
	Post() bool
	Put() bool
	Patch() bool
	Delete() bool
	Action(actionName ...string) bool
	Active(routeName string) bool
	Hx() bool
	Options() bool
	Head() bool
	Connect() bool
	Trace() bool
}

type Response

type Response interface {
	sender.ExtendableSend
	Status(statusCode int) Response
	Refresh() error
	Render(nodes ...gox.Node) error
	Intercept() Intercept
}

type Route

type Route struct {
	Lang       string
	Path       string
	Name       string
	Layout     layoutFactory
	Matcher    *regexp.Regexp
	Methods    []string
	Firewall   []firewall.Firewall
	PathValues []string
}

type RouteConfig

type RouteConfig struct {
	Type  int
	Value any
}

func Layout

func Layout(name string) RouteConfig

func Method

func Method(method ...string) RouteConfig

func Name

func Name(name string) RouteConfig

type Router

type Router interface {
	Static(path, dir string) Router
	Route(path any, handler Handler, config ...RouteConfig) Router
	Group(path any, name ...string) Router
}

type Slice

type Slice []Map

type State added in v0.1.6

type State interface {
	Get(key string, target any) error
	Save(key string, value any) error

	MustGet(key string, target any)
	MustSave(key string, value any)
}

type TestCtxParam

type TestCtxParam struct {
	Config         config.Config
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	MatchedRoute   *Route
	Routes         *[]*Route
}

type TestRouteParam

type TestRouteParam struct {
	Config  *config.Config
	Method  string
	Path    string
	TempDir string
	Body    io.Reader
	Handler func(c Ctx) error
}

Jump to

Keyboard shortcuts

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