pages

package
v2.17.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

templ: version: v0.3.898

templ: version: v0.3.898

templ: version: v0.3.898

Index

Constants

This section is empty.

Variables

View Source
var CounterConfig = routes.RouteConfig[CounterPageProps]{
	Type:       routes.STATIC,
	HttpMethod: routes.GET,
	Middleware: func(w http.ResponseWriter, r *http.Request) CounterPageProps {
		return nil
	},
	WasmCompression: routes.BROTLI,
	ClientSideState: func() {
		topic := GetCounterTopic()
		count := CreateObservable(0)

		Observe(func() {
			topic.Set(CounterState{Count: count.Get()})
		}, count)

		Observe(func() {
			SetText("counter-value", strconv.Itoa(count.Get()))
		}, count)

		CreateWasmFunc("increment", func() {
			count.Set(count.Get() + 1)
		})
	},
}
View Source
var IndexConfig = routes.RouteConfig[IndexPageProps]{
	Type:       routes.STATIC,
	HttpMethod: routes.GET,
	Middleware: func(w http.ResponseWriter, r *http.Request) IndexPageProps {
		return nil
	},
}

*

  • `IndexConfig` describes how this specific page should behave within the Gothic routing system. *
  • Options include:
  • - `Type`: Controls how the page is rendered:
  • - `STATIC` (default): Renders once and is cached.
  • - `DYNAMIC`: Runs middleware on every request.
  • - `ISR`: Regenerates at intervals you define (good for SEO + performance). *
  • - `HttpMethod`: Optionally define the HTTP method for HTMX to fetch this page (`GET`, `POST`, etc.). *
  • - `Middleware`: A function that receives the request and returns props for the page/component.
  • - For `STATIC`, runs once on first request.
  • - For `DYNAMIC`, runs on every request.
  • - For `ISR`, runs at the interval specified by `RevalidateInSec`. *
  • Cache backend is configured in `main.go` via `gothicRoutes.Setup()`:
  • - `CacheStrategy`: `CACHE_CONTROL_HEADERS` (default), `IN_MEMORY`, `REDIS`, or `LOCAL_FILES`.
  • - `CacheConfig.RedisURL` / `CacheConfig.RedisPassword`: Required for `REDIS`.
  • - `CacheConfig.CacheFilesPath`: Directory for `LOCAL_FILES` (default: `.gothic-cache`).
  • - `CacheConfig.Compression` / `CacheConfig.CompressionMethod`: Enable gzip or brotli compression.
View Source
var RevalidateConfig = routes.RouteConfig[RevalidateProps]{
	Type:       routes.ISR,
	HttpMethod: routes.GET,
	Middleware: func(w http.ResponseWriter, r *http.Request) RevalidateProps {
		return time.Now()
	},
	RevalidateInSec: 10,
}

*

  • `RevalidateConfig` defines the configuration for this ISR-enabled route. *
  • - `Type`: Set to `ISR` (Incremental Static Regeneration), allowing the page to be statically generated
  • and then revalidated in the background every `RevalidateInSec` seconds.
  • - `HttpMethod`: Sets the HTTP method this page responds to (in this case, GET).
  • - `Middleware`: Runs server-side to generate the props (`RevalidateProps`) for the page.
  • - `RevalidateInSec`: Specifies the revalidation interval in seconds (every 10 seconds). *
  • Cache backend is configured in main.go via gothicRoutes.Setup().
  • Default: CACHE_CONTROL_HEADERS in production, in-memory during development (hot-reload).

Functions

func Counter

func Counter(props CounterPageProps) templ.Component

func Index

func Index(props IndexPageProps) templ.Component

func Revalidate

func Revalidate(currentTime RevalidateProps) templ.Component

Types

type CounterPageProps

type CounterPageProps = interface{}

type IndexPageProps

type IndexPageProps = interface{}

*

  • Define the type of props your page or component will receive. *
  • This type must remain consistent across:
  • - `RouteConfig` (used to configure the route)
  • - `Middleware` (which injects the props)
  • - The page/component itself (as the props input) *
  • In this example, `IndexPageProps` is an empty interface, but you can define any structure that fits your needs.

type RevalidateProps

type RevalidateProps = time.Time

*

  • `RevalidateProps` defines the data (props) that this page receives from the middleware.
  • In this case, we’re passing a `time.Time` value that will be displayed in the page.

Jump to

Keyboard shortcuts

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