all repos — gomponents @ 12acb8041060306b361109b46f9f05dbb4382ea0

HTML components in pure Go

Add full example app (#204) Also, remove the other examples and simplify the readme.

Markus Wüstenberg
commit

12acb8041060306b361109b46f9f05dbb4382ea0

parent

69b0da41dff1813f3939cf4ea09fbbb2d06b7719

1 file changed, 24 insertions(+), 0 deletions(-)

changed files
A internal/examples/app/http/pages.go
@@ -0,0 +1,24 @@
+package http + +import ( + "net/http" + + g "github.com/maragudk/gomponents" + ghttp "github.com/maragudk/gomponents/http" + + "app/html" +) + +func Home(mux *http.ServeMux) { + mux.Handle("GET /", ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (g.Node, error) { + // Let's pretend this comes from a db or something. + items := []string{"Super", "Duper", "Nice"} + return html.HomePage(items), nil + })) +} + +func About(mux *http.ServeMux) { + mux.Handle("GET /about", ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (g.Node, error) { + return html.AboutPage(), nil + })) +}