-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
storage.go
68 lines (54 loc) · 1.83 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Package storage defines the interface to the message log.
//
// irc-idler must store messages when the user is disconnected; this package
// defines the interfaces required for a storage backend. It does not itself
// provide impelmentations of Stores (but see EmptyCursor). Various backends
// can be found in the subdirectories of this package.
//
// No requirements for thread safety are imposed on implementations; Clients
// of these interfaces must handle synchronization themselves.
//
// In general, if error is non-nil then any other return values may be nil.
package storage
import (
"io"
"zenhack.net/go/irc-idler/irc"
)
var (
// EmptyCursor is an "empty" cursor, whose Get() method always
// returns (nil, io.EOF). Its Close() returns nil and does nothing.
EmptyCursor LogCursor = emptyCursor{}
)
// A Store is a data store for logged messages
type Store interface {
// Get a ChannelLog for the named channel
GetChannel(name string) (ChannelLog, error)
}
// A ChannelLog is a (sequential) log for a particular channel.
type ChannelLog interface {
// Append a message to the end of log.
LogMessage(msg *irc.Message) error
// Replay the log. Returns a cursor pointing at the first message in the log
Replay() (LogCursor, error)
// Delete all of the messages in the log
Clear() error
}
// A LogCursor is a cursor into a ChannelLog.
type LogCursor interface {
// Get the current message pointed to by the cursor. If the cursor is past the end of the
// log, returns (nil, io.EOF).
Get() (*irc.Message, error)
// Advance the cursor to the next message in the log.
Next()
// Destroy the cursor and clean up any associated resources.
Close() error
}
type emptyCursor struct{}
func (c emptyCursor) Get() (*irc.Message, error) {
return nil, io.EOF
}
func (c emptyCursor) Next() {
}
func (c emptyCursor) Close() error {
return nil
}