/

not_found_handler.mdin: /docs/cmd/demo-server/


You can see an example of the custom 404 page here.

import (
	"net/http"

	"github.com/stanistan/veun"
	"github.com/stanistan/veun/el"
	"github.com/stanistan/veun/vhttp/handler"
	"github.com/stanistan/veun/vhttp/request"

	"github.com/stanistan/veun-http-demo/internal/view/doc_tree"
	"github.com/stanistan/veun-http-demo/internal/view/two_column"
)

404 not found

Repurpose the nav tree and the two-column view to have something that looks ok.

var notFoundView veun.AsView = veun.MustMemo(&two_column.View{
	Title: "404 Not Found",
	Nav:   doc_tree.View(""),
	Main: el.Article{
		el.H1{
			el.Text("404 Not Found"),
		},
		el.Hr{},
		el.P{
			el.A{el.Href("/"), el.Text("/ go home")},
		},
		el.P{
			el.Text("The content you were looking for was not found."),
		},
	},
})

This view is memoized and rendered when the server is started, but continues to be represented as a view in the typesystem.


The handler returns both the view and a handler that only sets the response code to 404.

var notFoundHandler = request.HandlerFunc(func(r *http.Request) (veun.AsView, http.Handler, error) {
	return notFoundView, handler.WithStatus(http.StatusNotFound), nil
})