app

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunGRPCServer

func RunGRPCServer(ctx context.Context, port string, db *sql.DB, log *logrus.Logger) error

RunGRPCServer initializes and runs the gRPC server.

func SetupGRPCServer

func SetupGRPCServer(tokenValidator TokenValidator, logger *logrus.Logger) *grpc.Server

Adding the interceptors to your gRPC server configuration

func StreamServerInterceptor

func StreamServerInterceptor(tokenValidator TokenValidator, logger *logrus.Logger) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new stream server interceptor for validating tokens.

func UnaryServerInterceptor

func UnaryServerInterceptor(tokenValidator TokenValidator, logger *logrus.Logger) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor for validating tokens.

Types

type AuthServer

type AuthServer struct {
	auth.UnimplementedAuthServiceServer
	DB                     *sql.DB
	Logger                 *logrus.Logger
	AccessTokenExpiration  time.Duration
	RefreshTokenExpiration time.Duration
}

AuthServer implements the AuthService.

func NewAuthServer

func NewAuthServer(db *sql.DB, logger *logrus.Logger, accessTokenExpiration, refreshTokenExpiration time.Duration) *AuthServer

NewAuthServer creates a new AuthServer with the given dependencies.

func (*AuthServer) GetPublicKeyBundle

func (*AuthServer) LoginUser

func (s *AuthServer) LoginUser(ctx context.Context, req *auth.LoginRequest) (*auth.LoginResponse, error)

LoginUser handles user login requests.

func (*AuthServer) RefreshToken

RefreshToken handles token refresh requests.

func (*AuthServer) RegisterUser

func (s *AuthServer) RegisterUser(ctx context.Context, req *auth.RegisterRequest) (*auth.RegisterResponse, error)

RegisterUser handles user registration requests.

func (*AuthServer) UploadPublicKeys

Implement the server-side handler for UploadPublicKeys

type ChatServiceServer

type ChatServiceServer struct {
	chat.UnimplementedChatServiceServer
	ActiveClients       map[uint32]chat.ChatService_StreamMessagesServer // Map from userID to their active stream
	UndeliveredMessages map[uint32][]*chat.MessageResponse               // Map from userID to their undelivered messages

	Logger *logrus.Logger
	// contains filtered or unexported fields
}

func NewChatServiceServer

func NewChatServiceServer(logger *logrus.Logger) *ChatServiceServer

func (*ChatServiceServer) IsActiveClient

func (s *ChatServiceServer) IsActiveClient(userID uint32) bool

IsActiveClient checks if a user is in the ActiveClients map.

func (*ChatServiceServer) StreamMessages

StreamMessages handles bidirectional message streaming between users.

type FriendsServer

type FriendsServer struct {
	friends.UnimplementedFriendManagementServer
	DB     *sql.DB
	Logger *logrus.Logger
}

FriendsServer implements the FriendsService.

func NewFriendsServer

func NewFriendsServer(db *sql.DB, logger *logrus.Logger) *FriendsServer

NewFriendsServer creates a new FriendsServer with the given dependencies.

func (*FriendsServer) AcceptFriendRequest

AcceptFriendRequest handles accepting a friend request.

func (*FriendsServer) DeclineFriendRequest

DeclineFriendRequest handles declining a friend request.

func (*FriendsServer) GetFriendList

GetFriendList retrieves the list of friends for the user.

func (*FriendsServer) GetIncomingFriendRequests

GetIncomingFriendRequests retrieves the incoming friend requests for the user.

func (*FriendsServer) GetOutgoingFriendRequests

GetOutgoingFriendRequests retrieves the outgoing friend requests sent by the user.

func (*FriendsServer) RemoveFriend

RemoveFriend handles removing a friend.

func (*FriendsServer) SendFriendRequest

SendFriendRequest handles sending a friend request.

type JWTTokenValidator

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

JWTTokenValidator is a struct that implements the TokenValidator interface using JWT.

func NewJWTTokenValidator

func NewJWTTokenValidator(secretKey string) *JWTTokenValidator

NewJWTTokenValidator creates a new instance of JWTTokenValidator.

func (*JWTTokenValidator) ValidateToken

func (v *JWTTokenValidator) ValidateToken(tokenString string) (string, string, error)

ValidateToken validates the JWT token and extracts the user ID and username.

type TokenValidator

type TokenValidator interface {
	ValidateToken(token string) (userID string, username string, err error)
}

TokenValidator interface defines the method for validating tokens.

Jump to

Keyboard shortcuts

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