Help us shape the future of Go! Take the 2026 Go Developer Survey

appevent

package
v1.3.100 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 14 Imported by: 1

Documentation

Overview

Package appevent pkg/app/appevent/broadcaster.go c2-vis-appsvc

Package appevent pkg/app/appevent/event.go c2-vis-appsvc

Package appevent pkg/app/appevent/handshake.go c2-vis-appsvc

Package appevent pkg/app/appevent/rpc.go c2-vis-appsvc

Package appevent pkg/app/appevent/subscriber.go c2-vis-appsvc

Package appevent pkg/app/appevent/types.go c2-vis-appsvc

Package appevent pkg/app/appevent/utils.go c2-vis-appsvc

Index

Constants

View Source
const TCPClose = "tcp_close"

TCPClose represents a close event.

View Source
const TCPDial = "tcp_dial"

TCPDial represents a dial event.

Variables

View Source
var (
	ErrSubscriptionsClosed = errors.New("event subscriptions is closed")
)

Errors associated with the Subscriber type.

Functions

func DoReqHandshake

func DoReqHandshake(conf appcommon.ProcConfig, subs *Subscriber) (net.Conn, []io.Closer, error)

DoReqHandshake performs a request handshake which is initiated from an app. First, it determines whether we need an egress connection (from the app server which sends events) by seeing if there are any subscriptions within 'subs'. If so, a listener is started. Then we send a hello object to the app server which contains the proc key and egress connection info (if needed).

func DoRespHandshake

func DoRespHandshake(ebc *Broadcaster, conn net.Conn) (*appcommon.Hello, error)

DoRespHandshake performs a response handshake from the app server side. It reads the hello object from the app, and connects the app to the events broadcast (if needed).

func PushEvent

func PushEvent(s *Subscriber, e *Event) error

PushEvent pushes an event to the relevant subscription channel.

Types

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Broadcaster combines multiple RPCClients (which connects to the RPCGateway of the apps). It is responsible for broadcasting events to apps (if the app is subscribed to the event type).

func NewBroadcaster

func NewBroadcaster(log logrus.FieldLogger, timeout time.Duration) *Broadcaster

NewBroadcaster instantiates a Broadcaster.

func (*Broadcaster) AddClient

func (mc *Broadcaster) AddClient(c RPCClient)

AddClient adds a RPCClient.

func (*Broadcaster) Broadcast

func (mc *Broadcaster) Broadcast(ctx context.Context, e *Event) error

Broadcast broadcasts an event to all subscribed channels of all rpc gateways.

func (*Broadcaster) Close

func (mc *Broadcaster) Close() error

Close implements io.Closer

func (*Broadcaster) SendTCPDial

func (eb *Broadcaster) SendTCPDial(ctx context.Context, remoteNet, remoteAddr string)

SendTCPDial sends tcp dial event

func (*Broadcaster) SendTPClose

func (eb *Broadcaster) SendTPClose(_ context.Context, netType, addr string)

SendTPClose sends transport close event

type Event

type Event struct {
	Type string
	Data []byte
	// contains filtered or unexported fields
}

Event represents an event that is to be broadcasted.

func NewEvent

func NewEvent(t string, v interface{}) *Event

NewEvent creates a new Event.

func (*Event) Done

func (e *Event) Done()

Done informs that event is handled.

func (*Event) InitDone

func (e *Event) InitDone()

InitDone enables the Done/Wait logic.

func (*Event) Unmarshal

func (e *Event) Unmarshal(v interface{})

Unmarshal unmarshals the event data to a given object.

func (*Event) Wait

func (e *Event) Wait()

Wait waits until event is handled.

type MockRPCClient

type MockRPCClient struct {
	mock.Mock
}

MockRPCClient is an autogenerated mock type for the RPCClient type

func NewMockRPCClient

func NewMockRPCClient(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockRPCClient

NewMockRPCClient creates a new instance of MockRPCClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockRPCClient) Close

func (_m *MockRPCClient) Close() error

Close provides a mock function with no fields

func (*MockRPCClient) Hello

func (_m *MockRPCClient) Hello() *appcommon.Hello

Hello provides a mock function with no fields

func (*MockRPCClient) Notify

func (_m *MockRPCClient) Notify(ctx context.Context, e *Event) error

Notify provides a mock function with given fields: ctx, e

type RPCClient

type RPCClient interface {
	io.Closer
	Notify(ctx context.Context, e *Event) error
	Hello() *appcommon.Hello
}

RPCClient describes the RPC client interface that communicates the NewRPCGateway.

func NewRPCClient

func NewRPCClient(hello *appcommon.Hello) (RPCClient, error)

NewRPCClient constructs a new 'rpcClient'.

type RPCGateway

type RPCGateway struct {
	// contains filtered or unexported fields
}

RPCGateway represents the RPC gateway that opens up an app for incoming events from visor.

func NewRPCGateway

func NewRPCGateway(log logrus.FieldLogger, subs *Subscriber) *RPCGateway

NewRPCGateway returns a new RPCGateway.

func (*RPCGateway) Notify

func (g *RPCGateway) Notify(e *Event, _ *struct{}) (err error)

Notify notifies the app about events.

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

Subscriber is used by apps and contain subscription channels to different event types.

func NewSubscriber

func NewSubscriber() *Subscriber

NewSubscriber returns a new Subscriber struct.

func (*Subscriber) Close

func (s *Subscriber) Close() error

Close implements io.Closer

func (*Subscriber) Count

func (s *Subscriber) Count() int

Count returns the number of subscriptions.

func (*Subscriber) OnTCPClose

func (s *Subscriber) OnTCPClose(action func(data TCPCloseData))

OnTCPClose subscribes to the OnTCPClose event channel (if not already). And triggers the contained action func on each subsequent event.

func (*Subscriber) OnTCPDial

func (s *Subscriber) OnTCPDial(action func(data TCPDialData))

OnTCPDial subscribes to the OnTCPDial event channel (if not already). And triggers the contained action func on each subsequent event.

func (*Subscriber) Subscriptions

func (s *Subscriber) Subscriptions() map[string]bool

Subscriptions returns a map of all subscribed event types.

type TCPCloseData

type TCPCloseData struct {
	RemoteNet  string `json:"remote_net"`
	RemoteAddr string `json:"remote_addr"`
}

TCPCloseData contains net close event data.

func (TCPCloseData) Type

func (TCPCloseData) Type() string

Type returns the TCPClose type.

type TCPDialData

type TCPDialData struct {
	RemoteNet  string `json:"remote_net"`
	RemoteAddr string `json:"remote_addr"`
}

TCPDialData contains net dial event data.

func (TCPDialData) Type

func (TCPDialData) Type() string

Type returns the TCPDial type.

Jump to

Keyboard shortcuts

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