cable_grpc

package
v0.0.0-...-4be293a Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IsAuthenticatedKey = "isAuthenticated"
	UserIDKey          = "userID"
)
View Source
const (
	CmdMessage     = "message"
	CmdPing        = "ping"
	CmdSubscribe   = "subscribe"
	CmdUnsubscribe = "unsubscribe"

	WelcomeMessage                     = `{"type": "welcome"}`
	ConnectionUnauthorizedMessage      = `{"type":"disconnect", "reason":"unauthorized", "reconnect": false}`
	ConfirmSubscriptionMessageTemplate = `{"identifier": "%s", "type": "confirm_subscription"}`
	RejectSubscriptionMessageTemplate  = `{"identifier": "%s", "type": "reject_subscription"}`
)

Variables

This section is empty.

Functions

func HydraAuthenticationFunc

func HydraAuthenticationFunc(ctx context.Context, accessToken string) (userID string, err error)

func LoggingUnaryInterceptor

func LoggingUnaryInterceptor(log *logrus.Entry) func(context.Context, interface{}, *grpc.UnaryServerInfo, grpc.UnaryHandler) (interface{}, error)

LoggingUnaryInterceptor returns a gRPC unary interceptor that logs all incoming gRPC calls. It logs the method details, request, response, and any potential errors.

Types

type AuthenticationFunc

type AuthenticationFunc func(ctx context.Context, accessToken string) (userID string, err error)

AuthenticationFunc is used to authenticate a user based on the provided access token.

type Channel

type Channel interface {
	// Authorize checks if the user is authorized to subscribe to the channel,
	// based on the provided user ID and channel identifier.
	Authorize(ctx context.Context, userID string, ident map[string]string) error
	// GetStreams returns a list of streams that the user should be subscribed to
	// or unsubscribe from, based on the provided user ID and channel identifier.
	GetStreams(ctx context.Context, userID string, ident map[string]string) []string
}

Channel represents a single communication path, supporting authorization and multiple streams subscription

type ConnIdentifier

type ConnIdentifier struct {
	AccessToken string
}

ConnIdentifier is used to identify a specific connection through its AccessToken.

type Server

type Server struct {
	pb.UnimplementedRPCServer

	Channels map[string]Channel

	WithAuthentication bool
	AuthenticationFunc AuthenticationFunc

	Logger *logrus.Entry
}

Server encapsulates the AnyCable RPC server functionalities.

func (*Server) Command

func (s *Server) Command(ctx context.Context, in *pb.CommandMessage) (*pb.CommandResponse, error)

func (*Server) Connect

func (*Server) Disconnect

func (s *Server) Disconnect(ctx context.Context, in *pb.DisconnectRequest) (*pb.DisconnectResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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