zebou

package module
v2.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

README

zebou

Documentation

Overview

Package zebou is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

This section is empty.

Variables

View Source
var File_zebou_proto protoreflect.FileDescriptor
View Source
var NoPeerFromContext = errors.New("no peer in attached in context")
View Source
var SessionNotFound = errors.New("session not found")

Functions

func Broadcast

func Broadcast(ctx context.Context, msg *ZeMsg) error

func RegisterNodesHandler

func RegisterNodesHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterNodesHandler registers the http handlers for service Nodes to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterNodesHandlerClient

func RegisterNodesHandlerClient(ctx context.Context, mux *runtime.ServeMux, client NodesClient) error

RegisterNodesHandlerClient registers the http handlers for service Nodes to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "NodesClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "NodesClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "NodesClient" to call the correct interceptors.

func RegisterNodesHandlerFromEndpoint

func RegisterNodesHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterNodesHandlerFromEndpoint is same as RegisterNodesHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterNodesHandlerServer

func RegisterNodesHandlerServer(ctx context.Context, mux *runtime.ServeMux, server NodesServer) error

RegisterNodesHandlerServer registers the http handlers for service Nodes to "mux". UnaryRPC :call NodesServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterNodesHandlerFromEndpoint instead.

func RegisterNodesServer

func RegisterNodesServer(s grpc.ServiceRegistrar, srv NodesServer)

func Send

func Send(ctx context.Context, msg *ZeMsg) error

Types

type Client

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

func Connect

func Connect(address string, config *tls.Config) *Client

func (*Client) GetMessage

func (c *Client) GetMessage() (*ZeMsg, error)

func (*Client) Send

func (c *Client) Send(msgType string, name string, o interface{}) error

func (*Client) SendMsg

func (c *Client) SendMsg(msg *ZeMsg) error

func (*Client) SetConnectionSateHandler

func (c *Client) SetConnectionSateHandler(h ConnectionStateHandler)

func (*Client) Stop

func (c *Client) Stop() error

type ConnectionStateHandler

type ConnectionStateHandler interface {
	ConnectionState(active bool)
}

type ConnectionStateHandlerFunc

type ConnectionStateHandlerFunc func(bool)

func (ConnectionStateHandlerFunc) ConnectionState

func (f ConnectionStateHandlerFunc) ConnectionState(active bool)

type HandleMessageFunc

type HandleMessageFunc func(msg *ZeMsg)

type Handler

type Handler interface {
	NewClient(ctx context.Context, info *PeerInfo)
	ClientQuit(ctx context.Context, info *PeerInfo)
	OnMessage(ctx context.Context, msg *ZeMsg)
}

Handler is a convenience for hub clients activity handler

type Hub

type Hub struct {
	UnimplementedNodesServer
	// contains filtered or unexported fields
}

func Serve

func Serve(l net.Listener, handler Handler) (*Hub, error)

func (*Hub) Broadcast

func (s *Hub) Broadcast(ctx context.Context, msg *ZeMsg)

Broadcast dispatches msg

func (*Hub) ClientSendChannelFromContext

func (s *Hub) ClientSendChannelFromContext(ctx context.Context) (Sender, error)

ClientSendChannelFromContext returns the client session associated with peer info in context

func (*Hub) GetClientSendChannel

func (s *Hub) GetClientSendChannel(id string) (Sender, error)

GetClientSendChannel returns the client session associated with id

func (*Hub) Send

func (s *Hub) Send(ctx context.Context, msg *ZeMsg) error

Send sends a message to the client associated with context It loads peer info in context to identify client

func (*Hub) SendTo

func (s *Hub) SendTo(id string, msg *ZeMsg) error

SendTo sends a message to the client associated with id

func (*Hub) Stop

func (s *Hub) Stop() error

Stop stops the listening for connections and free all current sessions

func (*Hub) Sync

func (s *Hub) Sync(stream Nodes_SyncServer) error

type MessageHandler

type MessageHandler interface {
	Handle(message *ZeMsg)
}

MessageHandler is a convenience for message handler

type NodesClient

type NodesClient interface {
	Sync(ctx context.Context, opts ...grpc.CallOption) (Nodes_SyncClient, error)
}

NodesClient is the client API for Nodes service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewNodesClient

func NewNodesClient(cc grpc.ClientConnInterface) NodesClient

type NodesServer

type NodesServer interface {
	Sync(Nodes_SyncServer) error
	// contains filtered or unexported methods
}

NodesServer is the server API for Nodes service. All implementations must embed UnimplementedNodesServer for forward compatibility

type Nodes_SyncClient

type Nodes_SyncClient interface {
	Send(*ZeMsg) error
	Recv() (*ZeMsg, error)
	grpc.ClientStream
}

type Nodes_SyncServer

type Nodes_SyncServer interface {
	Send(*ZeMsg) error
	Recv() (*ZeMsg, error)
	grpc.ServerStream
}

type PeerInfo

type PeerInfo struct {
	ID      string
	Address string
}

func Peer

func Peer(ctx context.Context) *PeerInfo

type Sender

type Sender interface {
	Send(message *ZeMsg) error
}

Sender is a convenience for message sender

type UnimplementedNodesServer

type UnimplementedNodesServer struct {
}

UnimplementedNodesServer must be embedded to have forward compatible implementations.

func (UnimplementedNodesServer) Sync

type UnsafeNodesServer

type UnsafeNodesServer interface {
	// contains filtered or unexported methods
}

UnsafeNodesServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to NodesServer will result in compilation errors.

type ZeMsg

type ZeMsg struct {
	Type    string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Id      string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	Encoded []byte `protobuf:"bytes,3,opt,name=encoded,proto3" json:"encoded,omitempty"`
	// contains filtered or unexported fields
}

func (*ZeMsg) Descriptor deprecated

func (*ZeMsg) Descriptor() ([]byte, []int)

Deprecated: Use ZeMsg.ProtoReflect.Descriptor instead.

func (*ZeMsg) GetEncoded

func (x *ZeMsg) GetEncoded() []byte

func (*ZeMsg) GetId

func (x *ZeMsg) GetId() string

func (*ZeMsg) GetType

func (x *ZeMsg) GetType() string

func (*ZeMsg) ProtoMessage

func (*ZeMsg) ProtoMessage()

func (*ZeMsg) ProtoReflect

func (x *ZeMsg) ProtoReflect() protoreflect.Message

func (*ZeMsg) Reset

func (x *ZeMsg) Reset()

func (*ZeMsg) String

func (x *ZeMsg) String() string

Jump to

Keyboard shortcuts

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