go: github.com/caoxuwen/go/services/bifrost/sse Index | Files

package sse

import "github.com/caoxuwen/go/services/bifrost/sse"

Index

Package Files

main.go mock.go server.go

type AddressEvent Uses

type AddressEvent string

AddressEvent is an event sent to address SSE stream.

const (
    TransactionReceivedAddressEvent AddressEvent = "transaction_received"
    AccountCreatedAddressEvent      AddressEvent = "account_created"
    ExchangedEvent                  AddressEvent = "exchanged"
    ExchangedTimelockedEvent        AddressEvent = "exchanged_timelocked"
)

type Event Uses

type Event struct {
    Address string       `db:"address"`
    Event   AddressEvent `db:"event"`
    Data    string       `db:"data"`
}

type MockServer Uses

type MockServer struct {
    mock.Mock
}

MockServer is a mockable SSE server.

func (*MockServer) BroadcastEvent Uses

func (m *MockServer) BroadcastEvent(address string, event AddressEvent, data []byte)

func (*MockServer) CreateStream Uses

func (m *MockServer) CreateStream(address string)

func (*MockServer) HTTPHandler Uses

func (m *MockServer) HTTPHandler(w http.ResponseWriter, r *http.Request)

func (*MockServer) StartPublishing Uses

func (m *MockServer) StartPublishing() error

func (*MockServer) StreamExists Uses

func (m *MockServer) StreamExists(address string) bool

type Server Uses

type Server struct {
    Storage Storage `inject:""`
    // contains filtered or unexported fields
}

func (*Server) BroadcastEvent Uses

func (s *Server) BroadcastEvent(address string, event AddressEvent, data []byte)

func (*Server) CreateStream Uses

func (s *Server) CreateStream(address string)

func (*Server) HTTPHandler Uses

func (s *Server) HTTPHandler(w http.ResponseWriter, r *http.Request)

func (*Server) StartPublishing Uses

func (s *Server) StartPublishing() error

StartPublishing starts publishing events from the shared storage.

func (*Server) StreamExists Uses

func (s *Server) StreamExists(address string) bool

type ServerInterface Uses

type ServerInterface interface {
    BroadcastEvent(address string, event AddressEvent, data []byte)
    StartPublishing() error
    CreateStream(address string)
    StreamExists(address string) bool
    HTTPHandler(w http.ResponseWriter, r *http.Request)
}

type Storage Uses

type Storage interface {
    // AddEvent adds a new server-sent event to the storage.
    AddEvent(event Event) error
    // GetEventsSinceID returns all events since `id`. Used to load and publish
    // all broadcasted events.
    // It returns the last event ID, list of events or error.
    // If `id` is equal `-1`:
    //    * it should return the last event ID and empty list if at least one
    //      event has been broadcasted.
    //    * it should return 0 if no events have been broadcasted.
    GetEventsSinceID(id int64) (int64, []Event, error)
}

Storage contains history of sent events. Because each transaction and Stellar account is always processed by a single Bifrost server, we need to broadcast events in case client streams events from the other Bifrost server.

It's used to broadcast events to all instances of Bifrost server and to handle clients' reconnections.

Package sse imports 7 packages (graph) and is imported by 3 packages. Updated 2020-07-28. Refresh now. Tools for package owners.