generated from ElnuDev/go-project
Implent SSE feed
This commit is contained in:
parent
3a8179a99a
commit
b5ca22cd7d
2 changed files with 2 additions and 3 deletions
2
main.go
2
main.go
|
@ -48,7 +48,7 @@ func generateCounter() handler {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
break outer
|
break outer
|
||||||
case <-tick:
|
case <-tick:
|
||||||
fmt.Fprintf(w, "event: count\ndata: %d\n\n", i)
|
fmt.Fprintf(w, "event: count\ndata: <div>%d</div>\n\n", i)
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
|
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div hx-sse="connect:/api/counter">
|
<div hx-sse="connect:/api/counter swap:count" hx-swap="beforebegin">
|
||||||
<div hx-sse="swap:count"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<button hx-get="/api/click1" hx-swap="innerHTML">Click me!</button>
|
<button hx-get="/api/click1" hx-swap="innerHTML">Click me!</button>
|
||||||
<br>
|
<br>
|
||||||
|
|
Reference in a new issue