2015-04-29 21:54:44 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2019-01-27 07:53:07 +00:00
|
|
|
"errors"
|
2018-06-17 21:47:05 +00:00
|
|
|
"os"
|
|
|
|
|
2018-05-31 21:24:59 +00:00
|
|
|
"github.com/khlieng/dispatch/pkg/session"
|
2020-03-10 22:56:07 +00:00
|
|
|
"github.com/spf13/viper"
|
2015-04-29 21:54:44 +00:00
|
|
|
)
|
|
|
|
|
2020-03-10 22:56:07 +00:00
|
|
|
var DataPath directory
|
|
|
|
var ConfigPath directory
|
2015-04-29 21:54:44 +00:00
|
|
|
|
2020-03-10 22:56:07 +00:00
|
|
|
func Initialize() {
|
|
|
|
if viper.GetString("dir") != DefaultDirectory() {
|
|
|
|
DataPath = directory(viper.GetString("dir"))
|
|
|
|
ConfigPath = directory(viper.GetString("dir"))
|
|
|
|
} else {
|
|
|
|
DataPath = directory(viper.GetString("data"))
|
|
|
|
ConfigPath = directory(viper.GetString("conf"))
|
|
|
|
}
|
|
|
|
os.MkdirAll(DataPath.Root(), 0700)
|
|
|
|
os.MkdirAll(ConfigPath.Root(), 0700)
|
2016-01-07 22:59:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 07:53:07 +00:00
|
|
|
var (
|
|
|
|
ErrNotFound = errors.New("no item found")
|
|
|
|
)
|
|
|
|
|
2018-05-31 21:24:59 +00:00
|
|
|
type Store interface {
|
2018-06-01 02:16:38 +00:00
|
|
|
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)
|
2018-06-01 02:16:38 +00:00
|
|
|
GetServers(user *User) ([]*Server, error)
|
2019-01-27 07:53:07 +00:00
|
|
|
SaveServer(user *User, server *Server) error
|
2018-06-01 02:16:38 +00:00
|
|
|
RemoveServer(user *User, host string) error
|
|
|
|
|
|
|
|
GetChannels(user *User) ([]*Channel, error)
|
|
|
|
AddChannel(user *User, channel *Channel) error
|
|
|
|
RemoveChannel(user *User, server, channel string) error
|
2015-04-29 21:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 21:24:59 +00:00
|
|
|
type SessionStore interface {
|
2018-06-01 02:16:38 +00:00
|
|
|
GetSessions() ([]*session.Session, error)
|
2018-05-31 21:24:59 +00:00
|
|
|
SaveSession(session *session.Session) error
|
|
|
|
DeleteSession(key string) error
|
2015-04-29 21:54:44 +00:00
|
|
|
}
|
2016-01-15 01:27:30 +00:00
|
|
|
|
2018-05-31 21:24:59 +00:00
|
|
|
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()
|
2016-01-15 01:27:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 21:24:59 +00:00
|
|
|
type MessageSearchProvider interface {
|
|
|
|
SearchMessages(server, channel, q string) ([]string, error)
|
|
|
|
Index(id string, message *Message) error
|
|
|
|
Close()
|
2016-01-15 01:27:30 +00:00
|
|
|
}
|