ui

package
v0.0.0-...-8e868a9 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublicFile

func PublicFile(filepath string) string

PublicFile generates a relative URL to a public file.

func StaticFile

func StaticFile(filepath string) string

StaticFile generates a relative URL to a static file including a cache-buster query parameter.

Types

type LayoutFunc

type LayoutFunc func(*Request, gomponents.Node) gomponents.Node

LayoutFunc is a callback function intended to render your page node within a given layout. This is handled as a callback to automatically support HTMX requests so that you can respond with only the page content and not the entire layout. See Request.Render().

type Request

type Request struct {
	// Title stores the title of the page.
	Title string

	// Context stores the request context.
	Context echo.Context

	// CurrentPath stores the path of the current request.
	CurrentPath string

	// IsHome stores whether the requested page is the home page.
	IsHome bool

	// IsAuth stores whether the user is authenticated.
	IsAuth bool

	// IsAdmin stores whether the user is an admin.
	IsAdmin bool

	// AuthUser stores the authenticated user.
	AuthUser *ent.User

	// Metatags stores metatag values.
	Metatags struct {
		// Description stores the description metatag value.
		Description string

		// Keywords stores the keywords metatag values.
		Keywords []string
	}

	// CSRF stores the CSRF token for the given request.
	// This will only be populated if the CSRF middleware is in effect for the given request.
	// If this is populated, all forms must include this value otherwise the requests will be rejected.
	CSRF string

	// Htmx stores information provided by HTMX about this request.
	Htmx *htmx.Request

	// Config stores the application configuration.
	// This will only be populated if the Config middleware is installed in the router.
	Config *config.Config
}

Request encapsulates information about the incoming request in order to provide your ui with important and useful information needed for rendering.

func NewRequest

func NewRequest(ctx echo.Context) *Request

NewRequest generates a new Request using the Echo context of a given HTTP request.

func (*Request) Path

func (r *Request) Path(routeName string, routeParams ...any) string

Path generates a URL path for a given route name and optional route parameters. This will only work if you've supplied names for each of your routes. It's optional to use and helps avoids having duplicate, hard-coded paths and parameters all over your application.

func (*Request) Render

func (r *Request) Render(layout LayoutFunc, node gomponents.Node) error

Render renders a given node, optionally within a given layout based on the HTMX request headers. If the request is being made by HTMX and is not boosted, this will automatically only render the node without the layout, to support partial rendering.

func (*Request) Url

func (r *Request) Url(routeName string, routeParams ...any) string

Url generates an absolute URL for a given route name and optional route parameters.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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