dispatch/storage/storage.go

65 lines
1.5 KiB
Go
Raw Normal View History

package storage
import (
2019-01-27 07:53:07 +00:00
"errors"
"os"
"github.com/khlieng/dispatch/pkg/session"
)
2020-04-20 01:02:15 +00:00
var Path directory
2020-04-20 01:02:15 +00:00
func Initialize(root, dataRoot, configRoot string) {
if root != DefaultDirectory() {
Path.dataRoot = root
Path.configRoot = root
} else {
2020-04-20 01:02:15 +00:00
Path.dataRoot = dataRoot
Path.configRoot = configRoot
}
2020-04-20 01:02:15 +00:00
os.MkdirAll(Path.DataRoot(), 0700)
os.MkdirAll(Path.ConfigRoot(), 0700)
2016-01-07 22:59:38 +00:00
}
2019-01-27 07:53:07 +00:00
var (
ErrNotFound = errors.New("no item found")
)
type Store interface {
GetUsers() ([]*User, error)
SaveUser(user *User) error
DeleteUser(user *User) error
2019-01-27 07:53:07 +00:00
GetServer(user *User, host string) (*Server, error)
GetServers(user *User) ([]*Server, error)
2019-01-27 07:53:07 +00:00
SaveServer(user *User, server *Server) error
RemoveServer(user *User, host string) error
GetChannels(user *User) ([]*Channel, error)
AddChannel(user *User, channel *Channel) error
RemoveChannel(user *User, server, channel string) error
GetOpenDMs(user *User) ([]Tab, error)
AddOpenDM(user *User, server, nick string) error
RemoveOpenDM(user *User, server, nick string) error
}
type SessionStore interface {
GetSessions() ([]*session.Session, error)
SaveSession(session *session.Session) error
DeleteSession(key string) error
}
type MessageStore interface {
LogMessage(message *Message) error
GetMessages(server, channel string, count int, fromID string) ([]Message, bool, error)
GetMessagesByID(server, channel string, ids []string) ([]Message, error)
Close()
}
type MessageSearchProvider interface {
SearchMessages(server, channel, q string) ([]string, error)
Index(id string, message *Message) error
Close()
}