mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
examples: minor (see previous commits)
examples: 3rd-party sse (2): add the same client-side as the original 3rd-party example
This commit is contained in:
parent
bccd5eb388
commit
61f04ee4ff
23
_examples/response-writer/sse-third-party-2/index.html
Normal file
23
_examples/response-writer/sse-third-party-2/index.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SSE Examples</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<strong>Messages</strong>
|
||||||
|
<br>
|
||||||
|
<div id="messages"></div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
e1 = new EventSource('/events/channel-1');
|
||||||
|
e1.onmessage = function(event) {
|
||||||
|
document.getElementById('messages').innerHTML += 'Message on channel-1: ' + event.data + '<br>';
|
||||||
|
};
|
||||||
|
|
||||||
|
e2 = new EventSource('/events/channel-2');
|
||||||
|
e2.onmessage = function(event) {
|
||||||
|
document.getElementById('messages').innerHTML += 'Message on channel-2: ' + event.data + '<br>';
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -11,8 +11,10 @@ import (
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Install the sse third-party package
|
// Install the sse third-party package.
|
||||||
// $ go get -u github.com/alexandrevicenzi/go-sse
|
// $ go get -u github.com/alexandrevicenzi/go-sse
|
||||||
|
//
|
||||||
|
// Documentation: https://pkg.go.dev/github.com/alexandrevicenzi/go-sse
|
||||||
func main() {
|
func main() {
|
||||||
s := sse.NewServer(&sse.Options{
|
s := sse.NewServer(&sse.Options{
|
||||||
// Increase default retry interval to 10s.
|
// Increase default retry interval to 10s.
|
||||||
|
@ -35,7 +37,7 @@ func main() {
|
||||||
|
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
app.Get("/", func(ctx iris.Context) {
|
app.Get("/", func(ctx iris.Context) {
|
||||||
ctx.ServeFile("../static/index.html")
|
ctx.ServeFile("./index.html")
|
||||||
})
|
})
|
||||||
app.Get("/events/{channel}", iris.FromStd(s))
|
app.Get("/events/{channel}", iris.FromStd(s))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user