server

package
v0.0.0-...-71ef565 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatServer

type ChatServer struct {

	// UnimplementedChatServiceServer must be embedded to have forwarded compatible implementations.
	chat.UnimplementedChatServiceServer
	// contains filtered or unexported fields
}

func NewChatServer

func NewChatServer(store *Store, cfg *config.Config) *ChatServer

func (*ChatServer) Connect

func (s *ChatServer) Connect(stream chat.ChatService_ConnectServer) error

func (*ChatServer) CreateRoom

func (s *ChatServer) CreateRoom(ctx context.Context, request *chat.CreateRoomRequest) (*chat.CreateRoomResponse, error)

type Connection

type Connection struct {
	UserID     string
	RoomID     string
	Unread     []*Message
	MessagesCh chan *Message
	Disconnect func()
}

type Message

type Message struct {
	Number    int
	RoomID    string
	UserID    string
	Text      string
	CreatedAt time.Time
}

func (*Message) MarshalBinary

func (m *Message) MarshalBinary() (data []byte, err error)

func (*Message) UnmarshalBinary

func (m *Message) UnmarshalBinary(data []byte) error

type Room

type Room struct {
	ID      string
	OwnerID string
	Name    string
}

type RoomHub

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

func (*RoomHub) Connect

func (h *RoomHub) Connect(userID string, lastReadMessageNumber int64) *Connection

func (*RoomHub) ReceiveMessage

func (h *RoomHub) ReceiveMessage(ctx context.Context, message *Message) error

type Server

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

func NewServer

func NewServer(cfg *config.Config, rdb *redis.Client) (*Server, error)

func (*Server) Port

func (s *Server) Port() (int, error)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

type Store

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

func NewStorage

func NewStorage(rdb *redis.Client, cfg *config.Config) *Store

func (*Store) CreateRoom

func (s *Store) CreateRoom(ctx context.Context, userID string, name string) (*Room, error)

func (*Store) GetRoomHub

func (s *Store) GetRoomHub(ctx context.Context, roomID string) (*RoomHub, error)

func (*Store) LoadMessages

func (s *Store) LoadMessages(ctx context.Context, roomID string) (messages []*Message, lastNumber int, err error)

func (*Store) SaveMessage

func (s *Store) SaveMessage(ctx context.Context, message *Message) error

Jump to

Keyboard shortcuts

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