Documentation
¶
Index ¶
- func NewHTTPServer(addr string, mux *http.ServeMux) *http.Server
- func RetrieveErrorCode(err error) int
- func ServeStaticAssets(fs embed.FS) func(r *Router)
- func Validate[T interface{}](ctx *Context) (data *T, validationErrors map[string]string, ok bool)
- func ValidateEnvironmentVariables[T interface{}]() *T
- type App
- type AppConfig
- type BaseResourceController
- func (c *BaseResourceController) Create(ctx *Context) error
- func (c *BaseResourceController) Delete(ctx *Context) error
- func (c *BaseResourceController) Edit(ctx *Context) error
- func (c *BaseResourceController) Index(ctx *Context) error
- func (c *BaseResourceController) Show(ctx *Context) error
- func (c *BaseResourceController) Store(ctx *Context) error
- func (c *BaseResourceController) Update(ctx *Context) error
- type Context
- func (c *Context) Context() context.Context
- func (c *Context) DecodeJSON(v any) error
- func (ctx *Context) GetHeader(key string) string
- func (ctx *Context) MakeURL(name string, params map[string]string) (string, error)
- func (c *Context) Next()
- func (c *Context) PathValue(key string) string
- func (ctx *Context) Redirect(to string) error
- func (ctx *Context) RedirectBack() error
- func (c *Context) Render(component templ.Component) error
- func (c *Context) SendJSON(v interface{}, statuses ...int) error
- func (ctx *Context) SendSSE(name string, data string) error
- func (c *Context) SendText(text string, statuses ...int) error
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) SetSSEHeaders()
- func (c *Context) WantsJSON() bool
- func (c *Context) WithStatus(statusCode int) *Context
- type Error
- type ErrorHandler
- type Handler
- type Resource
- type ResourceController
- type ResourceControllerMethod
- type Route
- type Router
- func (r *Router) Any(pattern string, handler Handler) *Route
- func (r *Router) Delete(pattern string, handler Handler) *Route
- func (r *Router) Get(pattern string, handler Handler) *Route
- func (r *Router) Handle(pattern string, handler http.Handler)
- func (r *Router) MakeURL(name string, values map[string]string) (string, error)
- func (r *Router) Patch(pattern string, handler Handler) *Route
- func (r *Router) Post(pattern string, handler Handler) *Route
- func (r *Router) Put(pattern string, handler Handler) *Route
- func (r *Router) Render(pattern string, component templ.Component) *Route
- func (r *Router) Resource(pattern string, controller ResourceController) *Resource
- func (r *Router) Use(handler Handler)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RetrieveErrorCode ¶
func ServeStaticAssets ¶
ServeStaticAssets returns a provider, which serves static assets from the embed.FS.
func Validate ¶
Validate validates the request body or form values. It returns the data, the validation errors, and a boolean indicating if the data is valid.
func ValidateEnvironmentVariables ¶
func ValidateEnvironmentVariables[T interface{}]() *T
ValidateEnvironmentVariables validates the environment variables, and panics if any of the environment variables aren't correctly set.
Types ¶
type App ¶
type App struct { Config *AppConfig Router *Router ErrorHandler *ErrorHandler }
type BaseResourceController ¶ added in v0.0.7
type BaseResourceController struct{}
BaseResourceController is a base controller for resources.
func (*BaseResourceController) Create ¶ added in v0.0.7
func (c *BaseResourceController) Create(ctx *Context) error
func (*BaseResourceController) Delete ¶ added in v0.0.7
func (c *BaseResourceController) Delete(ctx *Context) error
func (*BaseResourceController) Edit ¶ added in v0.0.7
func (c *BaseResourceController) Edit(ctx *Context) error
func (*BaseResourceController) Index ¶ added in v0.0.7
func (c *BaseResourceController) Index(ctx *Context) error
func (*BaseResourceController) Show ¶ added in v0.0.7
func (c *BaseResourceController) Show(ctx *Context) error
func (*BaseResourceController) Store ¶ added in v0.0.7
func (c *BaseResourceController) Store(ctx *Context) error
func (*BaseResourceController) Update ¶ added in v0.0.7
func (c *BaseResourceController) Update(ctx *Context) error
type Context ¶ added in v0.0.8
type Context struct { ResponseWriter http.ResponseWriter Request *http.Request // contains filtered or unexported fields }
Context is a wrapper around http.ResponseWriter and *http.Request, that is augmented with some Caesar-specific methods.
func (*Context) DecodeJSON ¶ added in v0.0.8
DecodeJSON decodes the JSON body of the request into the provided value.
func (*Context) Next ¶ added in v0.0.8
func (c *Context) Next()
Next marks the middleware as having called the next handler in the chain.
func (*Context) RedirectBack ¶ added in v0.0.8
RedirectBack redirects the client to the previous page.
func (*Context) SetSSEHeaders ¶ added in v0.0.8
func (ctx *Context) SetSSEHeaders()
SetSSEHeaders sets the headers for Server-Sent Events
func (*Context) WantsJSON ¶ added in v0.0.8
WantsJSON returns true if the client accepts JSON responses.
func (*Context) WithStatus ¶ added in v0.0.8
type ErrorHandler ¶
type Resource ¶ added in v0.0.7
type Resource struct {
Routes map[ResourceControllerMethod]*Route
}
Resource is the struct that holds the routes for a resource controller.
func (*Resource) Exclude ¶ added in v0.0.7
func (res *Resource) Exclude(methods ...ResourceControllerMethod) *Resource
Exclude excludes methods from the resource.
type ResourceController ¶ added in v0.0.7
type ResourceController interface { // Index returns a list of resources. Index(ctx *Context) error // Create creates a new resource. Create(ctx *Context) error // Store creates a new resource. Store(ctx *Context) error // Show returns a single resource. Show(ctx *Context) error // Edit returns a form to edit a resource. Edit(ctx *Context) error // Update updates a resource. Update(ctx *Context) error // Delete deletes a resource. Delete(ctx *Context) error }
ResourceController is an interface for a controller that handles CRUD operations.
type ResourceControllerMethod ¶ added in v0.0.7
type ResourceControllerMethod string
ResourceControllerMethod is a type for the methods of a resource controller.
const ( MethodIndex ResourceControllerMethod = "Index" MethodCreate ResourceControllerMethod = "Create" MethodStore ResourceControllerMethod = "Store" MethodShow ResourceControllerMethod = "Show" MethodEdit ResourceControllerMethod = "Edit" MethodUpdate ResourceControllerMethod = "Update" MethodDelete ResourceControllerMethod = "Delete" )
type Route ¶
Route is a route that can be added to a Router.
type Router ¶
type Router struct { Routes []*Route Mux *http.ServeMux Middleware []Handler StandardRoutes map[string]http.Handler }
Router is a router that can be used to add routes.