Documentation ¶
Index ¶
- func AddLayout(r *http.Request, component string, props Props)
- func Error(component string) func(http.Handler) http.Handler
- func Layout(component string) func(http.Handler) http.Handler
- func New(fsys fs.FS) func(http.Handler) http.Handler
- func Page(component string) http.HandlerFunc
- func RenderError(w http.ResponseWriter, r *http.Request, message string, status int)
- func RenderPage(w http.ResponseWriter, r *http.Request, component string, props Props)
- func SetError(r *http.Request, component string)
- type Props
- type RenderContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLayout ¶
AddLayout appends the component to the request. Layouts consist of any components with a <slot>. Calling this multiple times on the same request will nest layouts.
func Error ¶
Error returns a middleware that calls SetError. Use this when there are no props needed to render the component. If you need to pass props, use SetError instead.
func Layout ¶
Layout returns a middleware that calls AddLayout. Use this when there are no props needed to render the component. If you need to pass props, use AddLayout instead.
func New ¶
New constructs a golte middleware from the given filesystem. The root of the filesystem should be the golte build directory.
The returned middleware is used to add a render context to incoming requests. It will allow you to use Layout, AddLayout, Page, and RenderPage. It should be mounted on the root of your router. The middleware should not be mounted on routes other than the root.
func Page ¶
func Page(component string) http.HandlerFunc
Page returns a handler that calls RenderPage. Use this when there are no props needed to render the component. If you need to pass props, use RenderPage instead.
func RenderError ¶
RenderError renders the current error page along with layouts. The error componenet will receive "message" and "status" as props. It will also write the status code to the header.
func RenderPage ¶
RenderPage renders the specified component. If any layouts were added previously, then each subsequent layout will go in the <slot> of the previous layout. The page will be in the <slot> of the last layout.
Types ¶
type Props ¶
Props is an alias for map[string]any. It exists for documentation purposes. Props must be JSON-serializable when passing to fuctions defined in this package.
type RenderContext ¶
type RenderContext struct { Renderer *render.Renderer Components []render.Entry ErrPage string // contains filtered or unexported fields }
RenderContext is used for lower level control over rendering. It allows direct access to the renderer and component slice.
func GetRenderContext ¶
func GetRenderContext(r *http.Request) *RenderContext
GetRenderContext returns the render context from the request, or nil if it doesn't exist.
func MustGetRenderContext ¶
func MustGetRenderContext(r *http.Request) *RenderContext
MustGetRenderContext is like GetRenderContext, but panics instead of returning nil.
func (*RenderContext) Render ¶
func (r *RenderContext) Render(w http.ResponseWriter)
Render renders all the components in the render context to the writer, with each subsequent component being a child of the previous.