add: chat service
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package svc
|
||||
|
||||
import "juwan-backend/app/chat/rpc/internal/config"
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Store *ChatStore
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Store: NewChatStore(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
)
|
||||
|
||||
type ChatStore struct {
|
||||
Mu sync.RWMutex
|
||||
|
||||
nextSessionID int64
|
||||
nextMessageID int64
|
||||
|
||||
Sessions map[int64]*pb.ChatSessions
|
||||
Messages map[int64]*pb.ChatMessages
|
||||
SessionMessages map[int64][]int64
|
||||
}
|
||||
|
||||
func NewChatStore() *ChatStore {
|
||||
return &ChatStore{
|
||||
nextSessionID: 1000,
|
||||
nextMessageID: 1000,
|
||||
Sessions: make(map[int64]*pb.ChatSessions),
|
||||
Messages: make(map[int64]*pb.ChatMessages),
|
||||
SessionMessages: make(map[int64][]int64),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ChatStore) NextSession() int64 {
|
||||
s.nextSessionID++
|
||||
return s.nextSessionID
|
||||
}
|
||||
|
||||
func (s *ChatStore) NextMessage() int64 {
|
||||
s.nextMessageID++
|
||||
return s.nextMessageID
|
||||
}
|
||||
Reference in New Issue
Block a user