all repos — gomponents @ 44b18894ac0195767a5882372a011be328000f40

HTML components in pure Go

Add example with dot imports (#47)

Markus Wüstenberg
commit

44b18894ac0195767a5882372a011be328000f40

parent

633b000d9115dbf7d4cc072cb1349268a09c3375

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

changed files
A examples/dot-import/dot-import.go
@@ -0,0 +1,37 @@
+package main + +import ( + "net/http" + + . "github.com/maragudk/gomponents" + . "github.com/maragudk/gomponents/components" + . "github.com/maragudk/gomponents/el" +) + +func main() { + _ = http.ListenAndServe("localhost:8080", http.HandlerFunc(handler)) +} + +func handler(w http.ResponseWriter, r *http.Request) { + p := page(props{ + title: r.URL.Path, + path: r.URL.Path, + }) + _ = p.Render(w) +} + +type props struct { + title string + path string +} + +func page(p props) Node { + return HTML5(DocumentProps{ + Title: p.title, + Language: "en", + Body: []Node{ + H1(p.title), + P(Textf("Welcome to the page at %v.", p.path)), + }, + }) +}