hello-world-reload.go 693 B

12345678910111213141516171819202122232425262728293031323334
  1. package e00_basics
  2. // @snippet_begin(HelloWorldReloadSample)
  3. import (
  4. "time"
  5. "github.com/qor5/web"
  6. . "github.com/theplant/htmlgo"
  7. )
  8. func HelloWorldReload(ctx *web.EventContext) (pr web.PageResponse, err error) {
  9. pr.Body = Div(
  10. H1("Hello World"),
  11. Text(time.Now().Format(time.RFC3339Nano)),
  12. Button("Reload Page").Attr("@click", web.GET().
  13. EventFunc(reloadEvent).
  14. Go()),
  15. )
  16. return
  17. }
  18. func update(ctx *web.EventContext) (er web.EventResponse, err error) {
  19. er.Reload = true
  20. return
  21. }
  22. const reloadEvent = "reload"
  23. var HelloWorldReloadPB = web.Page(HelloWorldReload).
  24. EventFunc(reloadEvent, update)
  25. const HelloWorldReloadPath = "/samples/hello_world_reload"
  26. // @snippet_end