Coder Social home page Coder Social logo

go-sse's People

Contributors

adminxvii avatar alexandrevicenzi avatar basebandit avatar bunin avatar kabaluyot avatar kataras avatar serverwentdown avatar wdscxsj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sse's Issues

"welcome" event

Greetings
Is it possible to send an event to a newly connected client?

Last Event ID

Does this package automatically send messages to a client based on their last event id or is that up to the person using this package?

I am attempting to figure out how to implement this, but am a little unclear about it.

Send SSE data only when it received POST method

Hi, newbie here. At the given example, it pushes tha data every 5sec. How can can I make the SSE push only when there's a POST(Hey subscribers, new data is coming!) method that kicks. Because I don't think it is wise to keep emitting even there's no new data.

Thank you in advance.

*middleware.compressResponseWriter is not http.CloseNotifier:

Hello!!!
Try using go-see with go-chi as a router by changing:

http.Handle("/events/", s)

by:

r.Mount("/events/", s)

but I get the following error:

panic: interface conversion: *middleware.compressResponseWriter is not http.CloseNotifier: missing method CloseNotify
...
.../github.com/alexandrevicenzi/go-sse/sse.go:82 +0x4c4

I hope you can help me

Data races

With [email protected] and when testing publishing from multiple browsers with race detector running, encountered race conditions.

WARNING: DATA RACE
Write at 0x00c000456258 by goroutine 68:
  github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
      /home/fat/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/channel.go:26 +0x87
  github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
      /home/fat/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/sse.go:117 +0x219
  projects/lib/channels.GenChannel.func1()
      /home/fat/projects/lib/channels/channels.go:121 +0x377

Previous write at 0x00c000456258 by goroutine 61:
  github.com/alexandrevicenzi/go-sse.(*Channel).SendMessage()
      /home/fat/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/channel.go:26 +0x87
  github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
      /home/fat/go/pkg/mod/github.com/alexandrevicenzi/[email protected]/sse.go:117 +0x219
  projects/lib/channels.GenChannel.func1()
      /home/fat/projects/lib/channels/channels.go:121 +0x377

Sorry, don't have the dump handy but had another data race on msg.retry write,

go-sse/sse.go

Line 94 in fcf9dce

msg.retry = s.options.RetryInterval

(which is being fed by SSE.SendMessage(chName, sse.NewMessage(strconv.Itoa(time.Now().Second()), string(msg), "msg")))

I'm using some complex code as well, so it's possible that I'm not 'doing it right', but these two data races under load seem to point at these two locations (channel.go:26 and sse.go:94)

Using with Echo?

Greetings
Is it possible to use this library with Labstatck's Echo framework?
TIA

Not safe for concurrent use

$ go run -race simple.go
2018/04/05 16:27:34 Listening at :3000
load: 2.81  cmd: simple 85940 running 0.01u 0.05s
==================
WARNING: DATA RACE
Write at 0x00c4200a4c90 by goroutine 6:
  runtime.mapassign_faststr()
      /Users/flowchartsman/opt/go/src/runtime/hashmap_fast.go:694 +0x0
  github.com/alexandrevicenzi/go-sse.(*Server).dispatch()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/sse.go:178 +0xe58

Previous read at 0x00c4200a4c90 by goroutine 8:
  runtime.mapaccess2_faststr()
      /Users/flowchartsman/opt/go/src/runtime/hashmap_fast.go:261 +0x0
  github.com/alexandrevicenzi/go-sse.(*Server).SendMessage()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/sse.go:100 +0x1e9
  main.main.func2()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/examples/simple.go:30 +0x74

Goroutine 6 (running) created at:
  github.com/alexandrevicenzi/go-sse.NewServer()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/sse.go:35 +0x237
  main.main()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/examples/simple.go:13 +0x3b

Goroutine 8 (running) created at:
  main.main()
      /Users/flowchartsman/gopath/src/github.com/alexandrevicenzi/go-sse/examples/simple.go:26 +0x156
==================

A casual inspection reveals racey map access in sse.go:

    } else if ch, ok := s.channels[channel]; ok { //this cannot be done concurrently
        if s.Debug {
            log.Printf("go-sse: message sent to channel '%s'.", ch.name)
        }
        ch.SendMessage(message)

Javascript client is receiving messages by batch

In a for loop, I am consuming a lot of stock data streams and publishing it in SSE. However upon checking the browser with the received SSE messages, they are received in batch, not pure real-time.

Is there any settings to tweak to make it work?

panic on graceful shutdown

Hello, when using the Shutdown method, I get a panic:

panic: send on closed channel

This is because the removeClient channel is closed before all HTTP handlers got closed.

I am a beginner, but to me it looks like we should never close removeClient.
But it will allow a goroutine leak, since goroutines trying to send on this channel will remain blocked.

I'll try to post a PR.

gofmt your code

$ gofmt -l *.go
channel.go
client.go
message.go
message_test.go
options.go
options_test.go
sse.go

Does not work with gzip.DefaultCompression

Hello,
I'm testing with gin and when r.Use(gzip.Gzip(gzip.DefaultCompression)) middleware is enabled, the messages are not displaied by browser console.
If I understand correctly, gzipping data breaks SSE api but I'm wondering if there is a work around to have best of both worlds?

Conditional logging

While library outputs are welcomed during development, they are annoying and useless in production.
Maybe conditional logging could be implemented to overcome this problem?

Multiple open tabs communicating

I have a situation where multiple tabs are communicating with the same server individually.
How do I make sure that each tab gets the right responses? The only thing I know is a dynamically generated tab id.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.