base

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameMessage

type FrameMessage func(data []byte) []byte

FrameMessage is a function type that allows wrapping of the message before sending it to the client

type Handler

type Handler struct {
	Sessions *collection.SyncMap[string, *Session]
	Logger   jsonrpc.Logger // Logger for error messages
}

Handler represents a jsonrpc endpoint

func NewHandler

func NewHandler() *Handler

func (*Handler) HandleMessage

func (e *Handler) HandleMessage(ctx context.Context, session *Session, data []byte, output *bytes.Buffer)

type Option

type Option func(s *Session)

Option represents option

func WithEventBuffer added in v0.6.0

func WithEventBuffer(size int) Option

WithEventBuffer sets size of in-memory event buffer for session so that server can re-deliver messages on Last-Event-ID reconnect.

func WithFramer

func WithFramer(framer FrameMessage) Option

type Session

type Session struct {
	Id         string `json:"id"`
	RoundTrips *transport.RoundTrips
	Writer     io.Writer
	Handler    transport.Handler

	RequestIdSeq uint64

	sync.Mutex
	// contains filtered or unexported fields
}

func NewSession

func NewSession(ctx context.Context, id string, writer io.Writer, newHandler transport.NewHandler, options ...Option) *Session

func (*Session) Error

func (s *Session) Error() error

Error returns error

func (*Session) EventsAfter added in v0.6.0

func (s *Session) EventsAfter(lastID uint64) [][]byte

EventsAfter returns buffered framed messages with id greater than lastID.

func (*Session) NextRequestID added in v0.7.1

func (s *Session) NextRequestID() jsonrpc.RequestId

func (*Session) SendData

func (s *Session) SendData(ctx context.Context, data []byte)

SendData sends data

func (*Session) SendError

func (s *Session) SendError(ctx context.Context, error *jsonrpc.Error)

SendError sends error

func (*Session) SendRequest

func (s *Session) SendRequest(ctx context.Context, request *jsonrpc.Request)

SendRequest sends response

func (*Session) SendResponse

func (s *Session) SendResponse(ctx context.Context, response *jsonrpc.Response)

SendResponse sends response

func (*Session) SetError

func (s *Session) SetError(err error)

SetError sets error

type Transport

type Transport struct {
	TripTimeout time.Duration
	// contains filtered or unexported fields
}

Transport represents a Transport

func NewTransport

func NewTransport(tripper *transport.RoundTrips, sendData func(ctx context.Context, data []byte), session *Session) *Transport

NewTransport creates a new Transport

func (*Transport) NextRequestID added in v0.7.1

func (s *Transport) NextRequestID() jsonrpc.RequestId

func (*Transport) Notify

func (s *Transport) Notify(ctx context.Context, notification *jsonrpc.Notification) error

func (*Transport) Send

func (s *Transport) Send(ctx context.Context, request *jsonrpc.Request) (*jsonrpc.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL