GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - scrhartley/go-templ-streaming-poc: Proof-of-concept for HTML streaming in Go using futures with Templ

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
static
static
 
 
templates
templates
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
main.go
main.go
 
 

Repository files navigation

Go Templ Streaming Proof-of-Concept

Proof-of-concept of HTML streaming in Go implemented with Templ templating. This implementation uses a function variant of the Future pattern (e.g. value()) as opposed to the approach implied by Templ's documentation of using channels directly (e.g. <-value). This has the advantage of being able to read each value multiple times if desired and also improves the ergonomics of flushing when dealing with a group of computations.

This repo also includes a take on the Error Boundary error-handling mechanism. Traditional page rendering will try to collect all the data and if there's an error during this process the backend can choose to return or redirect to an error page instead. This isn't as straightforward with streaming and error boundaries offer an alternative strategy by instead rendering fallback content for a section of the page if it has failed.

Template Usage:

@await() {
    <div>{ myData() }</div>
}

for data := range myConcurrentSeq {
    @await() {
      <div>{ data() }</div>
    }
}

@awaitFallible("<div>Failed to render this section</div>") {
    <div>{ myDataOrError() }</div>
}

@awaitFallible(fancyErrorFallback("Failed to render this section as well")) {
    <div>{ myDataOrError() }</div>
}

Endpoints:
/async (localhost:3000/async) - This is the primary page demonstrating the features in this repo. Due to concurrency, it may appear that most of the page completes simultaneously. The chance of this lessens when quicker computations are rendered before slower computations.
/sync (localhost:3000/sync) - This is included for comparison purposes and shows how the same page behaves when concurrency is not used (in terms of ordering and speed), while still using streaming.

Useful commands:
go tool templ generate - Updates generated code when changes are made to the Templ template files.
go run main.go - Will compile the code and run the server.

About

Proof-of-concept for HTML streaming in Go using futures with Templ

Topics

gohtml-streamingtempl

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.