pubsub

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpHeader

type HttpHeader struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type InMemory

type InMemory[T any] struct {
	// contains filtered or unexported fields
}

func NewInMemory

func NewInMemory[T any]() *InMemory[T]

func (*InMemory[T]) Publish

func (ps *InMemory[T]) Publish(ctx context.Context, topic string, event T) error

func (*InMemory[T]) Subscribe

func (ps *InMemory[T]) Subscribe(ctx context.Context, topic string) (<-chan T, func(), error)

type PubSub

type PubSub[T any] interface {
	Publisher[T]
	Subscriber[T]
}

type Publisher

type Publisher[T any] interface {
	// Publish an event into the topic.
	Publish(_ context.Context, topic string, event T) error
}

type Redis

type Redis[T any] struct {
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis[T any](c redisClient, encDec encoding.EncoderDecoder) *Redis[T]

func (*Redis[T]) Publish

func (ps *Redis[T]) Publish(ctx context.Context, topic string, event T) error

func (*Redis[T]) Subscribe

func (ps *Redis[T]) Subscribe(ctx context.Context, topic string) (_ <-chan T, unsubscribe func(), _ error)

type Request

type Request struct {
	ID                 string       `json:"id"`
	ClientAddr         string       `json:"client_addr"`
	Method             string       `json:"method"`
	Headers            []HttpHeader `json:"headers"`
	URL                string       `json:"url"`
	CreatedAtUnixMilli int64        `json:"created_at_unix_milli"`
}

type RequestAction

type RequestAction = string
const (
	RequestActionCreate RequestAction = "create" // create a request
	RequestActionDelete RequestAction = "delete" // delete a request
	RequestActionClear  RequestAction = "clear"  // delete all requests
)

type RequestEvent

type RequestEvent struct {
	Action  RequestAction `json:"action"`
	Request *Request      `json:"request"`
}

type Subscriber

type Subscriber[T any] interface {
	// Subscribe to the topic. The returned channel will receive events.
	// The returned function should be called to unsubscribe.
	Subscribe(_ context.Context, topic string) (_ <-chan T, unsubscribe func(), _ error)
}

Jump to

Keyboard shortcuts

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