/
type.go
68 lines (58 loc) · 1.97 KB
/
type.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 db
import (
pb "github.com/NetAuth/Protocol"
)
// DB specifies the methods that a DB engine must provide.
type DB interface {
// Entity handling
DiscoverEntityIDs() ([]string, error)
LoadEntity(string) (*pb.Entity, error)
SaveEntity(*pb.Entity) error
DeleteEntity(string) error
NextEntityNumber() (int32, error)
SearchEntities(SearchRequest) ([]*pb.Entity, error)
// Group handling
DiscoverGroupNames() ([]string, error)
LoadGroup(string) (*pb.Group, error)
SaveGroup(*pb.Group) error
DeleteGroup(string) error
NextGroupNumber() (int32, error)
SearchGroups(SearchRequest) ([]*pb.Group, error)
}
// Factory defines the function which can be used to register new
// implementations.
type Factory func() (DB, error)
// Callback is a function type registered by an external customer that
// is interested in some change that might happen in the storage
// system. These are returned with a DBEvent populated of whether or
// not the event pertained to an entity or a group, and the relavant
// primary key.
type Callback func(Event)
// Event is a type of message that can be fed to callbacks
// describing the event and the key of the thing that happened.
type Event struct {
Type EventType
PK string
}
// An EventType is used to specify what kind of event has happened and
// is constrained for consumption in downstream select cases. As
// these IDs are entirely internal and are maintained within a
// compiled version, iota is used here to make it easier to patch this
// list in the future.
type EventType int
// The callbacks defined below are used to signal what events are
// handled by the Event subsystem.
const (
EventEntityCreate EventType = iota
EventEntityUpdate
EventEntityDestroy
EventGroupCreate
EventGroupUpdate
EventGroupDestroy
)
// SearchRequest is an expression that can be interpreted by the
// default util search system, or translated by a storage layer to
// provide a more optimized searching experience.
type SearchRequest struct {
Expression string
}