Documentation ¶
Index ¶
- Constants
- Variables
- func Latest(a, b string) string
- type Announcements
- func (a *Announcements) CreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
- func (a *Announcements) GetMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
- func (a *Announcements) GetOrCreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
- func (a *Announcements) Namespace() string
- func (a *Announcements) Post(ctx context.Context, in *models.Announcement) (_ string, err error)
- func (a *Announcements) Recent(ctx context.Context, maxResults int, notBefore, start time.Time) (out *api.AnnouncementsReply, err error)
- func (a *Announcements) SaveMonth(ctx context.Context, month *models.AnnouncementMonth) (err error)
- type Collection
- type DB
- func (db *DB) Announcements() *Announcements
- func (db *DB) Close() error
- func (db *DB) Delete(ctx context.Context, key []byte, namespace string) (err error)
- func (db *DB) Get(ctx context.Context, key []byte, namespace string) (value []byte, err error)
- func (db *DB) Organizations() *Organizations
- func (db *DB) Put(ctx context.Context, key, value []byte, namespace string) (err error)
- type Organizations
- func (o *Organizations) Create(ctx context.Context) (org *models.Organization, err error)
- func (o *Organizations) Delete(ctx context.Context, orgID interface{}) (err error)
- func (o *Organizations) Namespace() string
- func (o *Organizations) Retrieve(ctx context.Context, orgID interface{}) (org *models.Organization, err error)
- func (o *Organizations) Update(ctx context.Context, org *models.Organization) (err error)
Constants ¶
const (
NamespaceAnnouncements = "announcements"
)
const (
NamespaceOrganizations = "organizations"
)
Variables ¶
var ( ErrNotFound = errors.New("key not found in database") ErrUnsuccessfulPut = errors.New("unable to successfully make Put request to trtl") ErrUnsuccessfulDelete = errors.New("unable to successfully make Delete request to trtl") ErrEmptyAnnouncement = errors.New("cannot post a zero-valued announcement") ErrUnboundedRecent = errors.New("cannot specify zero-valued not before otherwise announcements fetch is unbounded") )
Functions ¶
Types ¶
type Announcements ¶ added in v1.5.0
type Announcements struct {
// contains filtered or unexported fields
}
The Announcements type exposes methods for interacting with Network Announcements in the database. Announcements are stored as compact, compressed JSON to minimize the network requests and reduce storage requirements. This struct performs all necessary serialization on the announcements before storing and retrieving the model object. The announcement keys are ksuids - timestamp ordered unique IDs so that it is easy to scan the trtl database to find the most recent announcements.
Announcements implements the Collection interface
func (*Announcements) CreateMonth ¶ added in v1.5.0
func (a *Announcements) CreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
CreateMonth from a month timestamp in the form YYYY-MM.
func (*Announcements) GetMonth ¶ added in v1.5.0
func (a *Announcements) GetMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
GetMonth from a month timestamp in the form YYYY-MM.
func (*Announcements) GetOrCreateMonth ¶ added in v1.5.0
func (a *Announcements) GetOrCreateMonth(ctx context.Context, date string) (month *models.AnnouncementMonth, err error)
GetOrCreateMonth from a month timestamp in the form YYYY-MM.
func (*Announcements) Namespace ¶ added in v1.5.0
func (a *Announcements) Namespace() string
Namespace implements the collection interface
func (*Announcements) Post ¶ added in v1.5.0
func (a *Announcements) Post(ctx context.Context, in *models.Announcement) (_ string, err error)
Post an announcement, putting it to the trtl database. This method does no verification of duplicate announcements or any content verification except for a check that an empty announcement is not being put to the database. Announcements are stored in announcement months, so the month for the announcement is extracted and the announcement is inserted into the correct month, creating it if necessary.
func (*Announcements) Recent ¶ added in v1.5.0
func (a *Announcements) Recent(ctx context.Context, maxResults int, notBefore, start time.Time) (out *api.AnnouncementsReply, err error)
Recent returns the set of results whose post date is after the not before timestamp, limited to the maximum number of results. Last updated returns the timestamp that any announcement was added or changed.
type Collection ¶ added in v1.5.0
type Collection interface {
Namespace() string
}
Collection is an interface that identifies utilities that manage specific namespaces.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a wrapper around a trtl client to provide BFF-specific database interactions
func DirectConnect ¶
func DirectConnect(cc *grpc.ClientConn) (db *DB, err error)
func (*DB) Announcements ¶ added in v1.5.0
func (db *DB) Announcements() *Announcements
Announcements constructs the collection type for interactions with network announcement objects. This method is intended to be used with chaining, e.g. as db.Announcements().Recent(), so to reduce the number of allocations a singleton intermediate struct is used. Method calls to the collection are thread-safe.
func (*DB) Delete ¶ added in v1.5.0
Delete is a high-level method for executing a delete key-value request to a namespace in trtl.
func (*DB) Get ¶ added in v1.5.0
Get is a high-level method for executing a fetch key request to a namespace in trtl.
func (*DB) Organizations ¶ added in v1.5.0
func (db *DB) Organizations() *Organizations
Organizations constructs the collection type for db interactions with the namespace. This method is intended to be used with chaining, e.g. db.Organizations().Get(id). To reduce the number of allocations a singleton is used. Method calls to the collection are thread-safe.
type Organizations ¶ added in v1.5.0
type Organizations struct {
// contains filtered or unexported fields
}
The Organizations collection exposes methods for interacting with Organization records in the database. Organizations are given UUIDs when created, and those uuids are also used as keys in the database for quick Gets by ID.
Organizations implements the Collection interface
func (*Organizations) Create ¶ added in v1.5.0
func (o *Organizations) Create(ctx context.Context) (org *models.Organization, err error)
Create an organization and get back the organization stub.
func (*Organizations) Delete ¶ added in v1.5.0
func (o *Organizations) Delete(ctx context.Context, orgID interface{}) (err error)
Delete an organization by it's ID, which can be either a []byte, string, or uuid.
func (*Organizations) Namespace ¶ added in v1.5.0
func (o *Organizations) Namespace() string
Namespace implements the collection interface