app

package
v0.0.0-...-5a53ebd Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPInKey = "input"

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

func New

func New(optFuncs ...OptFunc) *App

func (*App) DB

func (app *App) DB() *db.DB

func (*App) DbFunc

func (app *App) DbFunc(c context.Context, config *db.Config) (*db.DB, error)

func (*App) FS

func (app *App) FS() fsys.FS

func (*App) HandleSignals

func (app *App) HandleSignals()

func (*App) Inertia

func (app *App) Inertia() *inertia.Inertia

func (*App) Plugin

func (app *App) Plugin(plugin Plugin) Plugin

func (*App) Plugins

func (app *App) Plugins() PluginRegistry

func (*App) RegisterRoutes

func (app *App) RegisterRoutes(fn RouteRegistrarFunc)

func (*App) Router

func (app *App) Router() *Router

func (*App) Run

func (app *App) Run()

func (*App) Session

func (app *App) Session() *session.Session

func (*App) SetDB

func (app *App) SetDB(db *db.DB)

func (*App) SetDbFunc

func (app *App) SetDbFunc(dbFunc func(c context.Context, config *db.Config) (*db.DB, error))

func (*App) SetSession

func (app *App) SetSession(session *session.Session)

type AppHooks

type AppHooks struct {
	BeforeStart func()
	AfterStart  func()
}

type AppManager

type AppManager interface {
	Plugin(Plugin) Plugin
	Plugins() PluginRegistry
	Router() *Router
	Session() *session.Session
	Inertia() *inertia.Inertia
	DB() *db.DB
	DbFunc(c context.Context, config *db.Config) (*db.DB, error)
	FS() fsys.FS
}

type AuthServiceProvider

type AuthServiceProvider struct {
	*BaseServiceProvider
}

func (*AuthServiceProvider) Boot

func (provider *AuthServiceProvider) Boot()

func (*AuthServiceProvider) Register

func (provider *AuthServiceProvider) Register(app *App)

type BaseInput

type BaseInput struct {
	App       AppManager
	Ctx       *Context
	Validator *Validator
}

type BaseServiceProvider

type BaseServiceProvider struct {
	App *App
}

func (*BaseServiceProvider) Publishes

func (p *BaseServiceProvider) Publishes()

type Context

type Context struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Context) Alert

func (c *Context) Alert(typ string, message string) *res.AlertMessage

func (*Context) App

func (c *Context) App() AppManager

func (*Context) AuthUser

func (c *Context) AuthUser() interface{}

func (*Context) Back

func (c *Context) Back(status int) error

func (*Context) BadRequest

func (c *Context) BadRequest(err error) error

func (*Context) Body

func (c *Context) Body() (map[string][]string, error)

func (*Context) Cookie

func (c *Context) Cookie(name string) *http.Cookie

func (*Context) DB

func (c *Context) DB() *db.DB

func (*Context) DecodeJSON

func (c *Context) DecodeJSON(v interface{}) error

func (*Context) Download

func (c *Context) Download(path string, filename string) error

func (*Context) Error

func (c *Context) Error(status int, err error) error

func (*Context) FS

func (c *Context) FS() fsys.FS

func (*Context) File

func (c *Context) File(path string, headers ...map[string][]string) error

func (*Context) Forbidden

func (c *Context) Forbidden(err error) error

func (*Context) Form

func (c *Context) Form() (map[string][]string, error)

func (*Context) FormFile

func (c *Context) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

func (*Context) Get

func (c *Context) Get(key string) any

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetInput

func (c *Context) GetInput() any

func (*Context) GetSession

func (c *Context) GetSession(key string) any

func (*Context) GetSessionString

func (c *Context) GetSessionString(key string) string

func (*Context) HTML

func (c *Context) HTML(status int, body []byte) error

func (*Context) HasFile

func (c *Context) HasFile(key string) bool

func (*Context) HasFormURLEncodedRequest

func (c *Context) HasFormURLEncodedRequest() bool

func (*Context) HasMultiPartRequest

func (c *Context) HasMultiPartRequest() bool

func (*Context) I

func (c *Context) I() *inertia.Inertia

func (*Context) Inertia

func (c *Context) Inertia(status int, filePath string, props map[string]any) error

func (*Context) Input

func (c *Context) Input(inputStruct any) any

func (*Context) InternalServerError

func (c *Context) InternalServerError(err error) error

func (*Context) IsInertiaRequest

func (c *Context) IsInertiaRequest() bool

func (*Context) IsReading

func (c *Context) IsReading() bool

func (*Context) JSON

func (c *Context) JSON(status int, body M) error

func (*Context) Next

func (c *Context) Next() error

func (*Context) NotFound

func (c *Context) NotFound(err error) error

func (*Context) PageExpired

func (c *Context) PageExpired() error

func (*Context) Param

func (c *Context) Param(key string) string

func (*Context) ParseInput

func (c *Context) ParseInput(inputStruct any) error

func (*Context) Plugin

func (c *Context) Plugin(plugin Plugin) Plugin

func (*Context) PopSession

func (c *Context) PopSession(key string) any

func (*Context) PopSessionString

func (c *Context) PopSessionString(key string) string

func (*Context) PutSession

func (c *Context) PutSession(key string, value any) *Context

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) Redirect

func (c *Context) Redirect(status int, url string) error

func (*Context) Referer

func (c *Context) Referer() string

func (*Context) Render

func (c *Context) Render(status int, tmplPath string, data *res.TemplateData) error

func (*Context) Request

func (c *Context) Request() *http.Request

func (*Context) RequestContext

func (c *Context) RequestContext() context.Context

func (*Context) Respond

func (c *Context) Respond(r *R) error

func (*Context) ResponseWriter

func (c *Context) ResponseWriter() http.ResponseWriter

func (*Context) Set

func (c *Context) Set(key string, value interface{})

func (*Context) SetCookie

func (c *Context) SetCookie(name string, value string, maxAge int, path string, domain string, secure bool, httpOnly bool)

SetCookie sets a cookie on the response writer Example: // c.SetCookie("jwt", token, 60*60*24*7, "/", "", false, true)

func (*Context) SetHeader

func (c *Context) SetHeader(key string, value string)

func (*Context) SetInput

func (c *Context) SetInput(inputStruct any) error

func (*Context) SetRequest

func (c *Context) SetRequest(r *http.Request)

func (*Context) StorageFile

func (c *Context) StorageFile(path string, headers ...map[string][]string) error

func (*Context) Templ

func (c *Context) Templ(status int, component templ.Component) error

func (*Context) Text

func (c *Context) Text(status int, body []byte) error

func (*Context) Unauthorized

func (c *Context) Unauthorized(err error) error

func (*Context) Upload

func (c *Context) Upload(key string, dir string, filename ...string) (*os.File, error)

func (*Context) Validate

func (c *Context) Validate(body req.Validator) error

func (*Context) ValidationError

func (c *Context) ValidationError(err error) error

func (*Context) WantsHTML

func (c *Context) WantsHTML() bool

func (*Context) WantsJSON

func (c *Context) WantsJSON() bool

func (*Context) With

func (c *Context) With(key string, message string) *Context

func (*Context) WithData

func (c *Context) WithData(data map[string]any) *Context

func (*Context) WithError

func (c *Context) WithError(message string) *Context

func (*Context) WithErrors

func (c *Context) WithErrors(errors shared.ValidationErrors) *Context

func (*Context) WithInfo

func (c *Context) WithInfo(message string) *Context

func (*Context) WithInput

func (c *Context) WithInput() *Context

func (*Context) WithSuccess

func (c *Context) WithSuccess(message string) *Context

func (*Context) WithWarning

func (c *Context) WithWarning(message string) *Context

type DatabaseServiceProvider

type DatabaseServiceProvider struct {
	*BaseServiceProvider
}

func (*DatabaseServiceProvider) Boot

func (provider *DatabaseServiceProvider) Boot()

func (*DatabaseServiceProvider) Register

func (provider *DatabaseServiceProvider) Register(app *App)

type FileInput

type FileInput struct {
	*httpin.File
}

type Group

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

func (*Group) Delete

func (g *Group) Delete(pattern string, handlers ...Handler) *Route

func (*Group) Get

func (g *Group) Get(pattern string, handlers ...Handler) *Route

func (*Group) Group

func (g *Group) Group(prefix string) *Group

func (*Group) Patch

func (g *Group) Patch(pattern string, handlers ...Handler) *Route

func (*Group) Post

func (g *Group) Post(pattern string, handlers ...Handler) *Route

func (*Group) Put

func (g *Group) Put(pattern string, handlers ...Handler) *Route

func (*Group) UseAfter

func (g *Group) UseAfter(handlers ...Handler)

func (*Group) UseBefore

func (g *Group) UseBefore(handlers ...Handler)

type HTTPMiddleware

type HTTPMiddleware func(http.Handler) http.Handler

type Handler

type Handler func(c *Context) error

type InertiaFlashProvider

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

func NewInertiaFlashProvider

func NewInertiaFlashProvider() *InertiaFlashProvider

func (*InertiaFlashProvider) FlashErrors

func (p *InertiaFlashProvider) FlashErrors(ctx context.Context, errors inertia.ValidationErrors) error

func (*InertiaFlashProvider) GetErrors

type M

type M map[string]any

func (M) Error

func (m M) Error() string

type Middleware

type Middleware func(next Handler) Handler

func Input

func Input(inputStruct any, opts ...core.Option) Middleware

type OptFunc

type OptFunc func(opts *Options)

func WithFS

func WithFS(fs fsys.FS) OptFunc

func WithHooks

func WithHooks(hooks *AppHooks) OptFunc

func WithInertia

func WithInertia(i *inertia.Inertia) OptFunc

func WithPlugins

func WithPlugins(plugins map[PluginID]Plugin) OptFunc

func WithProviders

func WithProviders(providers []ServiceProvider) OptFunc

func WithSession

func WithSession(sm *session.Session) OptFunc

type Options

type Options struct {
	//*container.Container
	*session.Session
	Config           config.ConfigMap
	Plugins          map[PluginID]Plugin
	ServiceProviders []ServiceProvider

	Hooks *AppHooks
	// contains filtered or unexported fields
}

type Plugin

type Plugin interface {
	Boot(a AppManager) error
	InstallCommand() *cobra.Command
	Commands() []*cobra.Command
	EventListeners() map[string]func()
	PublishableMigrations() map[string][]byte
	PublishableModels() map[string][]byte
	PublishableTemplates() map[string][]byte
	Middlewares() []HTTPMiddleware
	Routes() []*Route
	Webhooks() []string
}

type PluginID

type PluginID string

type PluginRegistry

type PluginRegistry map[PluginID]Plugin

func (PluginRegistry) Add

func (r PluginRegistry) Add(plugin Plugin)

Add a plugin

func (PluginRegistry) Get

func (r PluginRegistry) Get(plugin Plugin) Plugin

Get a plugin

type R

type R struct {
	Status       int
	TemplateName string
	InertiaView  string
	Payload      M
	RedirectTo   string
}

type Route

type Route struct {
	Method           string
	Path             string
	Handlers         []Handler
	BeforeMiddleware []Handler
	AfterMiddleware  []Handler
	// contains filtered or unexported fields
}

func (*Route) UseAfter

func (r *Route) UseAfter(handlers ...Handler) *Route

func (*Route) UseBefore

func (r *Route) UseBefore(handlers ...Handler) *Route

type RouteRegistrarFunc

type RouteRegistrarFunc func(r *Router)

type Router

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

func NewRouter

func NewRouter() *Router

NewRouter creates a new HTTPRouter-based router

func (*Router) Connect

func (r *Router) Connect(pattern string, handlers ...Handler) *Route

func (*Router) Delete

func (r *Router) Delete(pattern string, handlers ...Handler) *Route

func (*Router) Get

func (r *Router) Get(pattern string, handlers ...Handler) *Route

func (*Router) Group

func (r *Router) Group(prefix string) *Group

func (*Router) Handle

func (r *Router) Handle(pattern string, handler http.Handler)

func (*Router) HandleFunc

func (r *Router) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*Router) HasRoute

func (r *Router) HasRoute(method string, pattern string) bool

func (*Router) Head

func (r *Router) Head(pattern string, handlers ...Handler) *Route

func (*Router) Options

func (r *Router) Options(pattern string, handlers ...Handler) *Route

func (*Router) Patch

func (r *Router) Patch(pattern string, handlers ...Handler) *Route

func (*Router) Post

func (r *Router) Post(pattern string, handlers ...Handler) *Route

func (*Router) Put

func (r *Router) Put(pattern string, handlers ...Handler) *Route

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Trace

func (r *Router) Trace(pattern string, handlers ...Handler) *Route

func (*Router) Use

func (r *Router) Use(middlewares ...HTTPMiddleware)

Use adds one or more standard net/http middleware to the router

func (*Router) UseAfter

func (r *Router) UseAfter(handlers ...Handler)

func (*Router) UseBefore

func (r *Router) UseBefore(handlers ...Handler)

type ServiceProvider

type ServiceProvider interface {
	Register(app *App)
	Boot()
}

type SessionServiceProvider

type SessionServiceProvider struct {
	*BaseServiceProvider
}

func (*SessionServiceProvider) Boot

func (provider *SessionServiceProvider) Boot()

func (*SessionServiceProvider) Register

func (provider *SessionServiceProvider) Register(app *App)

type StorageServiceProvider

type StorageServiceProvider struct {
	BaseServiceProvider
}

func (*StorageServiceProvider) Boot

func (provider *StorageServiceProvider) Boot()

func (*StorageServiceProvider) Register

func (provider *StorageServiceProvider) Register(app *App)

type VField

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

func (*VField) ActiveURL

func (f *VField) ActiveURL() *VField

ActiveURL checks if the URL is active and reachable

func (*VField) AfterDate

func (f *VField) AfterDate(afterDate time.Time) *VField

AfterDate checks if the date is after the specified date

func (*VField) Alpha

func (f *VField) Alpha() *VField

Alpha checks if the value contains only alphabetic characters

func (*VField) AlphaDash

func (f *VField) AlphaDash() *VField

AlphaDash checks if the string contains only alpha-numeric characters, dashes, or underscores

func (*VField) AlphaNumeric

func (f *VField) AlphaNumeric() *VField

AlphaNumeric checks if the value contains only alphanumeric characters

func (*VField) Ascii

func (f *VField) Ascii() *VField

Ascii checks if the string contains only ASCII characters

func (*VField) BeforeDate

func (f *VField) BeforeDate(beforeDate time.Time) *VField

BeforeDate checks if the date is before the specified date

func (*VField) Between

func (f *VField) Between(min, max int) *VField

Between checks if the value is between min and max (inclusive)

func (*VField) Boolean

func (f *VField) Boolean() *VField

Boolean checks if the value is a valid boolean

func (*VField) Contains

func (f *VField) Contains(substring string) *VField

Contains checks if the string contains the specified substring

func (*VField) Custom

func (f *VField) Custom(validateFunc func(v interface{}) (bool, string)) *VField

Custom allows defining a custom validation rule

func (*VField) Date

func (f *VField) Date(layout string) *VField

Date checks if the value is a valid date in the specified format

func (*VField) Dimensions

func (f *VField) Dimensions(width, height int) *VField

Dimensions checks if the image file has the specified dimensions

func (*VField) Distinct

func (f *VField) Distinct() *VField

Distinct checks if all elements in a slice are unique

func (*VField) Email

func (f *VField) Email() *VField

Email checks if the value is a valid email address

func (*VField) EndsWith

func (f *VField) EndsWith(suffix string) *VField

EndsWith checks if the string ends with the specified substring

func (*VField) Equals

func (f *VField) Equals(value interface{}) *VField

Equals checks if the value is equal to the provided value

func (*VField) Filled

func (f *VField) Filled() *VField

Filled checks if the value is not empty (for strings, slices, maps, and pointers)

func (*VField) ForEach

func (f *VField) ForEach(rules ...func(*VField) *VField) *VField

ForEach applies validation rules to each item in an array

func (*VField) HexColor

func (f *VField) HexColor() *VField

HexColor checks if the string is a valid hexadecimal color code

func (*VField) IP

func (f *VField) IP() *VField

IP checks if the value is a valid IP address (v4 or v6)

func (*VField) In

func (f *VField) In(validValues []string) *VField

In checks if the value is in the given slice of valid values

func (*VField) JSON

func (f *VField) JSON() *VField

JSON checks if the value is a valid JSON string

func (*VField) MacAddress

func (f *VField) MacAddress() *VField

MacAddress checks if the string is a valid MAC address

func (*VField) Max

func (f *VField) Max(max int) *VField

Max checks if the value is less than or equal to the maximum

func (*VField) MimeTypes

func (f *VField) MimeTypes(allowedTypes []string) *VField

MimeTypes checks if the file has one of the specified MIME types

func (*VField) Min

func (f *VField) Min(min int) *VField

Min checks if the value is greater than or equal to the minimum

func (*VField) Name

func (f *VField) Name() string

func (*VField) Numeric

func (f *VField) Numeric() *VField

Numeric checks if the value contains only numeric characters

func (*VField) Regex

func (f *VField) Regex(pattern string) *VField

Regex checks if the value matches the given regular expression

func (*VField) Required

func (f *VField) Required() *VField

Required checks if the value is not empty

func (*VField) SetValue

func (f *VField) SetValue(value interface{}) *VField

func (*VField) StartsWith

func (f *VField) StartsWith(prefix string) *VField

StartsWith checks if the string starts with the specified substring

func (*VField) Timezone

func (f *VField) Timezone() *VField

Timezone checks if the value is a valid timezone

func (*VField) ULID

func (f *VField) ULID() *VField

ULID checks if the string is a valid ULID

func (*VField) URL

func (f *VField) URL() *VField

URL checks if the value is a valid URL

func (*VField) UUID

func (f *VField) UUID() *VField

UUID checks if the value is a valid UUID

func (*VField) Unique

func (f *VField) Unique(table string, column string, whereClauses ...map[string]interface{}) *VField

func (*VField) Value

func (f *VField) Value() interface{}

type Validator

type Validator struct {
	AppManager
	Errors shared.ValidationErrors
}

func NewValidator

func NewValidator(app AppManager) *Validator

func (*Validator) AddError

func (v *Validator) AddError(field, message string)

func (*Validator) ErrorsJSON

func (v *Validator) ErrorsJSON() map[string][]string

func (*Validator) Field

func (v *Validator) Field(name string, value interface{}) *VField

Field creates a new Field instance for chaining validation rules

func (*Validator) IsValid

func (v *Validator) IsValid() bool

func (*Validator) Validate

func (v *Validator) Validate() error

Jump to

Keyboard shortcuts

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