Documentation ¶
Index ¶
- func Close() error
- func DecodeUid(uid types.Uid) int64
- func EncodeUid(id int64) types.Uid
- func GetAdapterName() string
- func GetAdapterVersion() int
- func GetAuthHandler(name string) auth.AuthHandler
- func GetAuthNames() []string
- func GetDbVersion() int
- func GetLogicalAuthHandler(name string) auth.AuthHandler
- func GetMediaHandler() media.Handler
- func GetUid() types.Uid
- func GetUidString() string
- func GetValidator(name string) validate.Validator
- func InitAuthLogicalNames(config json.RawMessage) error
- func InitDb(jsonconf json.RawMessage, reset bool) error
- func IsOpen() bool
- func Open(workerId int, jsonconf json.RawMessage) error
- func RegisterAdapter(a adapter.Adapter)
- func RegisterAuthScheme(name string, handler auth.AuthHandler)
- func RegisterMediaHandler(name string, mh media.Handler)
- func RegisterValidator(name string, v validate.Validator)
- func UpgradeDb(jsonconf json.RawMessage) error
- func UseMediaHandler(name, config string) error
- type DeviceMapper
- type FileMapper
- type MessagesObjMapper
- func (MessagesObjMapper) DeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error
- func (MessagesObjMapper) GetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)
- func (MessagesObjMapper) GetDeleted(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Range, int, error)
- func (MessagesObjMapper) Save(msg *types.Message, readBySender bool) error
- type SubsObjMapper
- func (SubsObjMapper) Create(subs ...*types.Subscription) error
- func (SubsObjMapper) Delete(topic string, user types.Uid) error
- func (SubsObjMapper) Get(topic string, user types.Uid) (*types.Subscription, error)
- func (SubsObjMapper) Update(topic string, user types.Uid, update map[string]interface{}, updateTS bool) error
- type TopicsObjMapper
- func (TopicsObjMapper) Create(topic *types.Topic, owner types.Uid, private interface{}) error
- func (TopicsObjMapper) CreateP2P(initiator, invited *types.Subscription) error
- func (TopicsObjMapper) Delete(topic string, hard bool) error
- func (TopicsObjMapper) Get(topic string) (*types.Topic, error)
- func (TopicsObjMapper) GetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
- func (TopicsObjMapper) GetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
- func (TopicsObjMapper) GetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
- func (TopicsObjMapper) GetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
- func (TopicsObjMapper) OwnerChange(topic string, newOwner, oldOwner types.Uid) error
- func (TopicsObjMapper) Update(topic string, update map[string]interface{}) error
- type UsersObjMapper
- func (UsersObjMapper) AddAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, ...) (bool, error)
- func (UsersObjMapper) ConfirmCred(id types.Uid, method string) error
- func (UsersObjMapper) Create(user *types.User, private interface{}) (*types.User, error)
- func (UsersObjMapper) DelAuthRecords(uid types.Uid, scheme string) error
- func (UsersObjMapper) DelCred(id types.Uid, method, value string) error
- func (UsersObjMapper) Delete(id types.Uid, hard bool) error
- func (UsersObjMapper) FailCred(id types.Uid, method string) error
- func (UsersObjMapper) FindSubs(id types.Uid, required, optional []string) ([]types.Subscription, error)
- func (UsersObjMapper) Get(uid types.Uid) (*types.User, error)
- func (UsersObjMapper) GetActiveCred(id types.Uid, method string) (*types.Credential, error)
- func (UsersObjMapper) GetAll(uid ...types.Uid) ([]types.User, error)
- func (UsersObjMapper) GetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)
- func (UsersObjMapper) GetAuthRecord(user types.Uid, scheme string) (string, auth.Level, []byte, time.Time, error)
- func (UsersObjMapper) GetAuthUniqueRecord(scheme, unique string) (types.Uid, auth.Level, []byte, time.Time, error)
- func (UsersObjMapper) GetByCred(method, value string) (types.Uid, error)
- func (UsersObjMapper) GetDisabled(since time.Time) ([]types.Uid, error)
- func (UsersObjMapper) GetOwnTopics(id types.Uid, opts *types.QueryOpt) ([]string, error)
- func (UsersObjMapper) GetSubs(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
- func (UsersObjMapper) GetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
- func (UsersObjMapper) GetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
- func (UsersObjMapper) GetUnreadCount(id types.Uid) (int, error)
- func (UsersObjMapper) Update(uid types.Uid, update map[string]interface{}) error
- func (UsersObjMapper) UpdateAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, ...) (bool, error)
- func (UsersObjMapper) UpdateLastSeen(uid types.Uid, userAgent string, when time.Time) error
- func (UsersObjMapper) UpdateTags(uid types.Uid, add, remove, reset []string) ([]string, error)
- func (UsersObjMapper) UpsertCred(cred *types.Credential) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeUid ¶ added in v0.14.2
DecodeUid takes an XTEA encrypted Uid and decrypts it into an int64. This is needed for sql compatibility. Tte original int64 values are generated by snowflake which ensures that the top bit is unset.
func EncodeUid ¶ added in v0.14.2
EncodeUid applies XTEA encryption to an int64 value. It's the inverse of DecodeUid.
func GetAdapterName ¶ added in v0.14.6
func GetAdapterName() string
GetAdapterName returns the name of the current adater.
func GetAdapterVersion ¶ added in v0.16.0
func GetAdapterVersion() int
GetAdapterVersion returns version of the current adater.
func GetAuthHandler ¶
func GetAuthHandler(name string) auth.AuthHandler
GetAuthHandler returns an auth handler by actual hardcoded name irrspectful of logical naming.
func GetAuthNames ¶ added in v0.15.11
func GetAuthNames() []string
GetAuthNames returns all addressable auth handler names, logical and hardcoded excluding those which are disabled like "basic:".
func GetDbVersion ¶ added in v0.16.0
func GetDbVersion() int
GetDbVersion returns version of the underlying database.
func GetLogicalAuthHandler ¶ added in v0.15.7
func GetLogicalAuthHandler(name string) auth.AuthHandler
GetLogicalAuthHandler returns an auth handler by logical name. If there is no handler by that logical name it tries to find one by the hardcoded name.
func GetMediaHandler ¶ added in v0.15.2
GetMediaHandler returns default media handler.
func GetValidator ¶ added in v0.14.4
GetValidator returns registered validator by name.
func InitAuthLogicalNames ¶ added in v0.15.7
func InitAuthLogicalNames(config json.RawMessage) error
InitAuthLogicalNames initializes authentication mapping "logical handler name":"actual handler name". Logical name must not be empty, actual name could be an empty string.
func InitDb ¶
func InitDb(jsonconf json.RawMessage, reset bool) error
InitDb creates and configures a new database instance. If 'reset' is true it will first attempt to drop an existing database. If jsconf is nil it will assume that the adapter is already open. If it's non-nil and the adapter is not open, it will use the config string to open the adapter first.
func IsOpen ¶
func IsOpen() bool
IsOpen checks if persistent storage connection has been initialized.
func Open ¶
func Open(workerId int, jsonconf json.RawMessage) error
Open initializes the persistence system. Adapter holds a connection pool for a database instance.
name - name of the adapter rquested in the config file jsonconf - configuration string
func RegisterAdapter ¶ added in v0.14.2
func RegisterAdapter(a adapter.Adapter)
RegisterAdapter makes a persistence adapter available. If Register is called twice or if the adapter is nil, it panics.
func RegisterAuthScheme ¶
func RegisterAuthScheme(name string, handler auth.AuthHandler)
RegisterAuthScheme registers an authentication scheme handler. The 'name' must be the hardcoded name, NOT the logical name.
func RegisterMediaHandler ¶ added in v0.15.2
RegisterMediaHandler saves reference to a media handler (file upload-download handler).
func RegisterValidator ¶ added in v0.14.4
RegisterValidator registers validation scheme.
func UpgradeDb ¶ added in v0.16.0
func UpgradeDb(jsonconf json.RawMessage) error
UpgradeDb performes an upgrade of the database to the current adapter version. If jsconf is nil it will assume that the adapter is already open. If it's non-nil and the adapter is not open, it will use the config string to open the adapter first.
func UseMediaHandler ¶ added in v0.15.2
UseMediaHandler sets specified media handler as default.
Types ¶
type DeviceMapper ¶
type DeviceMapper struct{}
DeviceMapper is a struct to map methods used for handling device IDs, used to generate push notifications.
var Devices DeviceMapper
Devices is an instance of DeviceMapper to map methods to.
func (DeviceMapper) Delete ¶
func (DeviceMapper) Delete(uid types.Uid, deviceID string) error
Delete deletes device record for a given user.
type FileMapper ¶ added in v0.15.2
type FileMapper struct{}
FileMapper is a struct to map methods used for file handling.
var Files FileMapper
Files is an instance of FileMapper to be used for handling file uploads.
func (FileMapper) DeleteUnused ¶ added in v0.15.2
func (FileMapper) DeleteUnused(olderThan time.Time, limit int) error
DeleteUnused removes unused attachments.
func (FileMapper) FinishUpload ¶ added in v0.15.2
FinishUpload marks started upload as successfully finished.
func (FileMapper) Get ¶ added in v0.15.2
func (FileMapper) Get(fid string) (*types.FileDef, error)
Get fetches a file record for a unique file id.
func (FileMapper) StartUpload ¶ added in v0.15.2
func (FileMapper) StartUpload(fd *types.FileDef) error
StartUpload records that the given user initiated a file upload
type MessagesObjMapper ¶
type MessagesObjMapper struct{}
MessagesObjMapper is a struct to hold methods for persistence mapping for the Message object.
var Messages MessagesObjMapper
Messages is an instance of MessagesObjMapper to map methods to.
func (MessagesObjMapper) DeleteList ¶
func (MessagesObjMapper) DeleteList(topic string, delID int, forUser types.Uid, ranges []types.Range) error
DeleteList deletes multiple messages defined by a list of ranges.
func (MessagesObjMapper) GetAll ¶
func (MessagesObjMapper) GetAll(topic string, forUser types.Uid, opt *types.QueryOpt) ([]types.Message, error)
GetAll returns multiple messages.
type SubsObjMapper ¶
type SubsObjMapper struct{}
SubsObjMapper is A struct to hold methods for persistence mapping for the Subscription object.
var Subs SubsObjMapper
Subs is an instance of SubsObjMapper to map methods to.
func (SubsObjMapper) Create ¶
func (SubsObjMapper) Create(subs ...*types.Subscription) error
Create creates multiple subscriptions
func (SubsObjMapper) Delete ¶
func (SubsObjMapper) Delete(topic string, user types.Uid) error
Delete deletes a subscription
func (SubsObjMapper) Get ¶
func (SubsObjMapper) Get(topic string, user types.Uid) (*types.Subscription, error)
Get given subscription
type TopicsObjMapper ¶
type TopicsObjMapper struct{}
TopicsObjMapper is a struct to hold methods for persistence mapping for the topic object.
var Topics TopicsObjMapper
Topics is an instance of TopicsObjMapper to map methods to.
func (TopicsObjMapper) CreateP2P ¶
func (TopicsObjMapper) CreateP2P(initiator, invited *types.Subscription) error
CreateP2P creates a P2P topic by generating two user's subsciptions to each other.
func (TopicsObjMapper) Delete ¶
func (TopicsObjMapper) Delete(topic string, hard bool) error
Delete deletes topic, messages, attachments, and subscriptions.
func (TopicsObjMapper) Get ¶
func (TopicsObjMapper) Get(topic string) (*types.Topic, error)
Get a single topic with a list of relevant users de-normalized into it
func (TopicsObjMapper) GetSubs ¶
func (TopicsObjMapper) GetSubs(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
GetSubs loads a list of subscriptions to the given topic, user.Public and deleted subscriptions are not loaded
func (TopicsObjMapper) GetSubsAny ¶ added in v0.15.11
func (TopicsObjMapper) GetSubsAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
GetSubsAny loads a list of subscriptions to the given topic including deleted subscription. user.Public is not loaded
func (TopicsObjMapper) GetUsers ¶
func (TopicsObjMapper) GetUsers(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
GetUsers loads subscriptions for topic plus loads user.Public. Deleted subscriptions are not loaded.
func (TopicsObjMapper) GetUsersAny ¶
func (TopicsObjMapper) GetUsersAny(topic string, opts *types.QueryOpt) ([]types.Subscription, error)
GetUsersAny loads subscriptions for topic plus loads user.Public. It's the same as GetUsers, except it loads deleted subscriptions too.
func (TopicsObjMapper) OwnerChange ¶ added in v0.15.11
func (TopicsObjMapper) OwnerChange(topic string, newOwner, oldOwner types.Uid) error
OwnerChange replaces the old topic owner with the new owner.
type UsersObjMapper ¶
type UsersObjMapper struct{}
UsersObjMapper is a users struct to hold methods for persistence mapping for the User object.
var Users UsersObjMapper
Users is the ancor for storing/retrieving User objects
func (UsersObjMapper) AddAuthRecord ¶
func (UsersObjMapper) AddAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) (bool, error)
AddAuthRecord creates a new authentication record for the given user.
func (UsersObjMapper) ConfirmCred ¶ added in v0.14.4
func (UsersObjMapper) ConfirmCred(id types.Uid, method string) error
ConfirmCred marks credential method as confirmed.
func (UsersObjMapper) Create ¶
Create inserts User object into a database, updates creation time and assigns UID
func (UsersObjMapper) DelAuthRecords ¶ added in v0.14.4
func (UsersObjMapper) DelAuthRecords(uid types.Uid, scheme string) error
DelAuthRecords deletes user's auth records of the given scheme.
func (UsersObjMapper) DelCred ¶ added in v0.15.11
func (UsersObjMapper) DelCred(id types.Uid, method, value string) error
DelCred deletes user's credentials. If method is "", all credentials are deleted.
func (UsersObjMapper) Delete ¶
func (UsersObjMapper) Delete(id types.Uid, hard bool) error
Delete deletes user records.
func (UsersObjMapper) FailCred ¶ added in v0.14.4
func (UsersObjMapper) FailCred(id types.Uid, method string) error
FailCred increments fail count for the given credential method.
func (UsersObjMapper) FindSubs ¶
func (UsersObjMapper) FindSubs(id types.Uid, required, optional []string) ([]types.Subscription, error)
FindSubs find a list of users and topics for the given tags. Results are formatted as subscriptions.
func (UsersObjMapper) GetActiveCred ¶ added in v0.16.0
func (UsersObjMapper) GetActiveCred(id types.Uid, method string) (*types.Credential, error)
GetActiveCred gets a the currently active credential for the given user and method.
func (UsersObjMapper) GetAllCreds ¶ added in v0.16.0
func (UsersObjMapper) GetAllCreds(id types.Uid, method string, validatedOnly bool) ([]types.Credential, error)
GetAllCreds returns credentials of the given user, all or validated only.
func (UsersObjMapper) GetAuthRecord ¶
func (UsersObjMapper) GetAuthRecord(user types.Uid, scheme string) (string, auth.Level, []byte, time.Time, error)
GetAuthRecord takes a user ID and a authentication scheme name, fetches unique scheme-dependent identifier and authentication secret.
func (UsersObjMapper) GetAuthUniqueRecord ¶ added in v0.14.6
func (UsersObjMapper) GetAuthUniqueRecord(scheme, unique string) (types.Uid, auth.Level, []byte, time.Time, error)
GetAuthUniqueRecord takes a unique identifier and a authentication scheme name, fetches user ID and authentication secret.
func (UsersObjMapper) GetByCred ¶ added in v0.15.7
func (UsersObjMapper) GetByCred(method, value string) (types.Uid, error)
GetByCred returns user ID for the given validated credential.
func (UsersObjMapper) GetDisabled ¶ added in v0.15.11
GetDisabled returns user IDs which were disabled (soft-deleted) since specifid time.
func (UsersObjMapper) GetOwnTopics ¶ added in v0.15.11
GetOwnTopics retuens a slice of group topic names where the user is the owner.
func (UsersObjMapper) GetSubs ¶
func (UsersObjMapper) GetSubs(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
GetSubs loads a list of subscriptions for the given user. Does not load Public, does not load deleted subscriptions.
func (UsersObjMapper) GetTopics ¶
func (UsersObjMapper) GetTopics(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
GetTopics load a list of user's subscriptions with Public field copied to subscription
func (UsersObjMapper) GetTopicsAny ¶
func (UsersObjMapper) GetTopicsAny(id types.Uid, opts *types.QueryOpt) ([]types.Subscription, error)
GetTopicsAny load a list of user's subscriptions with Public field copied to subscription. Deleted topics are returned too.
func (UsersObjMapper) GetUnreadCount ¶ added in v0.16.0
func (UsersObjMapper) GetUnreadCount(id types.Uid) (int, error)
GetUnreadCount returs user's total count of unread messages in all topics with the R permissions
func (UsersObjMapper) Update ¶
func (UsersObjMapper) Update(uid types.Uid, update map[string]interface{}) error
Update is a generic user data update.
func (UsersObjMapper) UpdateAuthRecord ¶
func (UsersObjMapper) UpdateAuthRecord(uid types.Uid, authLvl auth.Level, scheme, unique string, secret []byte, expires time.Time) (bool, error)
UpdateAuthRecord updates authentication record with a new secret and expiration time.
func (UsersObjMapper) UpdateLastSeen ¶
UpdateLastSeen updates LastSeen and UserAgent.
func (UsersObjMapper) UpdateTags ¶ added in v0.14.2
UpdateTags either adds, removes, or resets tags to the given slices.
func (UsersObjMapper) UpsertCred ¶ added in v0.16.0
func (UsersObjMapper) UpsertCred(cred *types.Credential) (bool, error)
UpsertCred adds or updates a credential validation request. Return true if the record was inserted, false if updated.