...

Source file src/github.com/donovanhide/eventsource/interface.go

Documentation: github.com/donovanhide/eventsource

     1  // Package eventsource implements a client and server to allow streaming data one-way over a HTTP connection
     2  // using the Server-Sent Events API http://dev.w3.org/html5/eventsource/
     3  //
     4  // The client and server respect the Last-Event-ID header.
     5  // If the Repository interface is implemented on the server, events can be replayed in case of a network disconnection.
     6  package eventsource
     7  
     8  // Any event received by the client or sent by the server will implement this interface
     9  type Event interface {
    10  	// Id is an identifier that can be used to allow a client to replay
    11  	// missed Events by returning the Last-Event-Id header.
    12  	// Return empty string if not required.
    13  	Id() string
    14  	// The name of the event. Return empty string if not required.
    15  	Event() string
    16  	// The payload of the event.
    17  	Data() string
    18  }
    19  
    20  // If history is required, this interface will allow clients to reply previous events through the server.
    21  // Both methods can be called from different goroutines concurrently, so you must make sure they are go-routine safe.
    22  type Repository interface {
    23  	// Gets the Events which should follow on from the specified channel and event id.
    24  	Replay(channel, id string) chan Event
    25  }
    26  

View as plain text