The new version of iris.FromStd uses an error
func Hub() *iris.Application {
app := iris.New()
s := sse.New()
mvc.Configure(app.Party("/web"), func(mvc *mvc.Application) {
s.CreateStream("messages")
mvc.Router.Any("/events", iris.FromStd(s.HTTPHandler))
go func() {
ticker := time.NewTicker(time.Second * 2)
for range ticker.C {
fmt.Println("Time Out!")
s.Publish("messages",&sse.Event{
Data: []byte("ping"),
})
}
}()
mvc.Party("/audio").Register(services.NewAudioService()).Handle(new(web.AudioController))
})
return app
}
[HTTP Server] http: panic serving [::1]:52873: interface conversion: *context.responseWriter is not http.CloseNotifier: missing method CloseNotify
package main
import (
"github.com/kataras/iris/v12"
"github.com/r3labs/sse"
"time"
)
func main() {
app := iris.Default()
s := sse.New()
s.CreateStream("messages")
app.Any("/events", iris.FromStd(s.HTTPHandler))
go func() {
for {
time.Sleep(1 * time.Second)
s.Publish("messages", &sse.Event{
Data: []byte("ping"),
})
time.Sleep(3 * time.Second)
s.Publish("messages", &sse.Event{
Data: []byte("second message"),
})
time.Sleep(2 * time.Second)
s.Publish("messages", &sse.Event{
Data: []byte("third message"),
})
}
}()
_ = app.Listen(":8080")
}
[WARN] 2021/12/14 15:52 Recovered from a route's Handler('iris/core/handlerconv.FromStd') GET /events?stream=messages HTTP/1.1 Host: localhost:8080 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Connection: keep-alive Sec-Ch-Ua: "Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99" Sec-Ch-Ua-Mobile: ?0 Sec-Ch-Ua-Platform: "Windows" Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
interface conversion: *context.responseWriter is not http.CloseNotifier: missing method CloseNotify C:/Program Files/Go/src/runtime/panic.go:1038 C:/Program Files/Go/src/runtime/iface.go:91 C:/Program Files/Go/src/runtime/iface.go:458 C:/Users/wu/go/pkg/mod/github.com/r3labs/[email protected]/http.go:60 C:/Program Files/Go/src/net/http/server.go:2047 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/handlerconv/from_std.go:25 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/context/context.go:492 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/router/handler.go:440 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/router/router.go:111 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/context/context.go:634 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/recover/recover.go:77 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/context/context.go:634 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/requestid/requestid.go:84 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/context/context.go:634 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/accesslog/accesslog.go:744 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/context/context.go:492 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/router/router.go:156 C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/router/router.go:339 C:/Program Files/Go/src/net/http/server.go:2879 C:/Program Files/Go/src/net/http/server.go:1930 C:/Program Files/Go/src/runtime/asm_amd64.s:1581
2021-12-14 15:52:42|515.2µs|500|GET|/events|::1|stream=messages|0 B|21 B|error(interface conversion: *context.responseWriter is not http.CloseNotifier: missing method CloseNotify C:/Users/wu/go/pkg/mod/github.com/kataras/iris/[email protected]/core/handlerconv/from_std.go:24)|
Hello @ezewu I don't know what version of sse you used, please follow the example below:
package main
import (
"time"
"github.com/kataras/iris/v12"
"github.com/r3labs/sse/v2"
)
// $ go get github.com/r3labs/sse/[email protected]
func main() {
app := iris.New()
s := sse.New()
/*
This creates a new stream inside of the scheduler.
Seeing as there are no consumers, publishing a message
to this channel will do nothing.
Clients can connect to this stream once the iris handler is started
by specifying stream as a url parameter, like so:
http://localhost:8080/events?stream=messages
*/
s.CreateStream("messages")
app.Any("/events", iris.FromStd(s))
go func() {
// You design when to send messages to the client,
// here we just wait 5 seconds to send the first message
// in order to give u time to open a browser window...
time.Sleep(5 * time.Second)
// Publish a payload to the stream.
s.Publish("messages", &sse.Event{
Data: []byte("ping"),
})
time.Sleep(3 * time.Second)
s.Publish("messages", &sse.Event{
Data: []byte("second message"),
})
time.Sleep(2 * time.Second)
s.Publish("messages", &sse.Event{
Data: []byte("third message"),
})
}() // ...
app.Listen(":8080")
}
/* For a golang SSE client you can look at: https://github.com/r3labs/sse#example-client */
Write this sse like this. The latest iris report is 500