Documentation ¶
Index ¶
- Constants
- Variables
- func CheckExists(id string) func(*bolt.Tx) error
- func CheckNotExist(id string) func(*bolt.Tx) error
- func Delete(id []byte) func(tx *bolt.Tx) error
- func DeleteMessages(id string) func(*bolt.Tx) error
- func Get(c *Convo, id string) func(*bolt.Tx) error
- func GetAll(user string, filters ...users.Filter) func(*bolt.Tx) ([]*Convo, error)
- func InitMessages(id string) func(*bolt.Tx) error
- func IsExists(err error) bool
- func IsMissing(err error) bool
- func IsUnauthorized(err error) bool
- func Upsert(c *Convo) func(tx *bolt.Tx) error
- type Connected
- type ConnectionNotif
- type Convo
- type Deleted
- type Disconnected
- type Entry
- type Message
- type Removed
- type Scribe
- func (s Scribe) CheckExists(tx *bolt.Tx) error
- func (s Scribe) Checkin(tx *bolt.Tx) (uint64, bool, error)
- func (s Scribe) Checkout(id uint64, tx *bolt.Tx) (bool, error)
- func (s Scribe) DeleteCheckins(tx *bolt.Tx) error
- func (s Scribe) Hangup(db *bolt.DB) error
- func (s Scribe) Spawn(tx *bolt.Tx) error
- type Sender
Constants ¶
const ConvoMessage int = 1
const Frequency = 1 * time.Second
Frequency is the frequency with which the Scribe writes to the log.
const MaxBuffer = 128
MaxBuffer is the maximum number of messages which will be buffered before writing them to disk.
Variables ¶
var ( ConvoBucket = store.Bucket("convos") ScribeBucket = store.Bucket("scribes") MessageBucket = store.Bucket("messages") )
Bucket constants.
Functions ¶
func CheckExists ¶
CheckExists returns a function which returns nil if the Convo with the given ID exists.
func CheckNotExist ¶
CheckNotExist returns a function which returns nil if the Convo with the given ID does not exist.
func DeleteMessages ¶
DeleteMessages deletes a Message bucket. Don't use this until the Scribe has been hung up.
func GetAll ¶
GetAll returns a function which unmarshals all convos for which the user has ownership. If Filters are passed, only convos for which filter.Member(convo) == true will be returned.
func InitMessages ¶
InitMessages initializes a Message bucket for the given Stream ID.
func IsUnauthorized ¶
Types ¶
type Connected ¶
type Connected ConnectionNotif
Connected is a ConnectionNotif for convo connection events
type ConnectionNotif ¶
ConnectionNotif is a base for convo Resourcers to create notifs. Implement store.Resourcer as a method on an alias of ConnectionNotif.
type Convo ¶
Convo is an alias for stream.Stream, i.e., it is a struct for controlling access and ownership of a websocket based connection.
func (*Convo) Connected ¶
Connected returns a store.Resourcer which can notify that a user has connected.
func (*Convo) Disconnected ¶
Disconnected returns a store.Resourcer which can notify that a user has disconnected.
type Deleted ¶
type Deleted string
Deleted is a Resourcer which can notify that the convo has been deleted.
type Disconnected ¶
type Disconnected ConnectionNotif
Disconnected is a Resourcer which can notify that a user has disconnected.
func (Disconnected) Resource ¶
func (Disconnected) Resource() store.Resource
Resource implements Resourcer.Resource on Disconnected.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is a Scribe log entry. Its key is an RFC3339 timestamp and its value is the JSON representation of the message.
type Message ¶
type Message struct { Sender string `json:"sender"` Content string `json:"content"` Timestamp time.Time `json:"timestamp"` }
Message is a container for a convo message.
type Removed ¶
type Removed string
Removed is a Resourcer which can notify that the user has been removed from the Convo without showing the user the Convo.
type Scribe ¶
type Scribe string
Scribe is a BUS consumer which does nothing but log received messages to the Messages bucket under its ID (which is the same ID as the stream it belongs to.)
func (Scribe) CheckExists ¶
CheckExists is a bolt View function which returns nil if the given Scribe is already running. The Scribe should have the same ID as the Stream it is logging. If the Scribe does not exist, this returns errNotExists.
func (Scribe) Checkin ¶
Checkin is a bolt Update function which a sequence ID, and true, if the caller is the first caller for the given Scribe. If this returns true, the caller should also use Scribe.Spawn to start a new Scribe.
func (Scribe) Checkout ¶
Checkout is a bolt Update function which takes a sequence ID, and returns true if it is the last to check out. If it is the last to check out, the caller should also call Scribe.Hangup.
func (Scribe) DeleteCheckins ¶
DeleteCheckins deletes the Checkin / Checkout bucket for the Scribe. Only use this once all convo members have disconnected.
func (Scribe) Spawn ¶
Spawn is a Bolt Update function which creates a new Scribe Bus, listening to the given stream in a goroutine. It also creates a Responder, so the Scribe can be hung up. To hang it up and clean it from the database, use Scribe.Hangup.
TODO: Tighten this up using DB funcs in message.go.
type Sender ¶
Sender is a User who reads stream.Messages from a websocket Conn and binds their contents into a new convo.Message with the attached user.
func (Sender) Read ¶
Read is a SocketReader for passing to ws.Bind which wraps a received stream.Message contents with the Sender's userID in a convo.Message, and marshals the convo.Message into bytes.
A false bool return value indicates a normal or non-fatal error, such as a syntax error, so that the caller will know to notify the sender and continue to the next Read.