Documentation ¶
Index ¶
- Variables
- func AddGenericEventHandler(eventName string, f func([]byte)) (deleter func())
- func AddWatchEvent[T any](tableName string, f func(T))
- func AuthenticateUserByPassword(ctx context.Context, usernameOrEmail, passwordInput string) (uint64, error)
- func BuildCrossNodeToken(ctx context.Context, data []byte) (string, error)
- func BuildHalfToken(ctx context.Context, userId uint64) (string, error)
- func CreatePasswordUser(ctx context.Context, opts UserPasswordCreateOpts) (userId uint64, err error)
- func CreateSession(ctx context.Context, token string, userId uint64, jobId string) error
- func DeleteTasks(ctx context.Context, taskIds ...string) (deleted bool, err error)
- func EditAndPublish(ctx context.Context, tableName string, f func(context.Context) error, ...) error
- func ExtendTask(ctx context.Context, taskId string, in time.Duration) (extended bool, err error)
- func GetCrossNodeToken(ctx context.Context, token string) ([]byte, error)
- func GetGuildScanners(ctx context.Context, guildIds []uint64) (guildScanners []func(any) error, err error)
- func GetHalfToken(ctx context.Context, token string) (uint64, error)
- func GetMemberGuilds(ctx context.Context, hostname string, memberID uint64) (guilds []string, err error)
- func GetPGPKey(maker func() (pubKey, privKey string)) (pubKey, privKey string, err error)
- func HasOwner(ctx context.Context) bool
- func Init(pgConnectionUrl, redisConnectionUrl string) error
- func InternallyAddTask(ctx context.Context, task *Task, in time.Duration) (string, error)
- func InternallyConsumeConfig(handler func(key string, value json.RawMessage)) error
- func InternallyDeleteAllUserIDTokens(ctx context.Context, userId uint64) ([]string, error)
- func InternallyDeleteToken(ctx context.Context, token string) (string, error)
- func InternallyGetTokenJobID(ctx context.Context, token string) (string, error)
- func Migrate() error
- func PublishGenericEvent(eventName string, data []byte) error
- func ScanUserFromToken(ctx context.Context, token string, user any) error
- func SetupKey(ctx context.Context) (string, error)
- func UpdateConfig(ctx context.Context, key string, value any) error
- func UseGlobalLock[T any](ctx context.Context, lockName string, fn func() (T, error)) (val T, err error)
- type CreatePasswordUserError
- type Task
- type UserFlag
- type UserPasswordCreateOpts
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCredentials = errors.New("invalid credentials")
ErrInvalidCredentials is used to define an error thrown by CheckPassword.
var ErrNotPasswordAuth = errors.New("user is not password authenticated")
ErrNotPasswordAuth is used to define an error thrown by CheckPassword.
Functions ¶
func AddGenericEventHandler ¶
AddGenericEventHandler is used to add an event handler for an event.
func AddWatchEvent ¶
AddWatchEvent is used to add an event to watch a table where the events are published. T should be the type that is the same as the JSON.
func AuthenticateUserByPassword ¶
func AuthenticateUserByPassword(ctx context.Context, usernameOrEmail, passwordInput string) (uint64, error)
AuthenticateUserByPassword is used to authenticate a user by their password. If there is an error, it will return either: a) Any other error - ignore the rest of this if this is the case. b) A half-authentication token - this is a special type of token that can be used to authenticate the user with a 2FA code. If this is the case, the error will be of type httperrors.HalfAuthentication and contain more information. c) ErrInvalidCredentials - this is returned if the credentials are invalid. d) ErrNotPasswordAuth - this is returned if the user is not using password authentication. !! PLEASE READ THE ABOVE CAREFULLY - THIS IS AUTHENTICATION, WE CANNOT AFFORD TO MAKE ERRORS !!
func BuildCrossNodeToken ¶
BuildCrossNodeToken is used to build a 2 min TTL token which can be used to connect to the gateway.
func BuildHalfToken ¶
BuildHalfToken is used to build a half token which can be used to link to a user ID and prove the first stage of authentication was successful.
func CreatePasswordUser ¶
func CreatePasswordUser(ctx context.Context, opts UserPasswordCreateOpts) (userId uint64, err error)
CreatePasswordUser is used to create a user with a password.
func CreateSession ¶
CreateSession is used to create a new session for a user ID.
func DeleteTasks ¶
DeleteTasks is used to delete task(s) from the database. Returns true for deleted if they all were.
func EditAndPublish ¶
func EditAndPublish(ctx context.Context, tableName string, f func(context.Context) error, metadata any) error
EditAndPublish is used to push an edit on a table and publish the event. This will block until the events are published, so you can be assured any events are done by the time this is over.
func ExtendTask ¶
ExtendTask is used to extend the scheduled time of a task.
func GetCrossNodeToken ¶
GetCrossNodeToken is used to get the data from a cross node token and destroy it at the same time.
func GetGuildScanners ¶
func GetGuildScanners(ctx context.Context, guildIds []uint64) (guildScanners []func(any) error, err error)
GetGuildScanners is used to get a guild scanner for every guild ID specified.
func GetHalfToken ¶
GetHalfToken is used to get the user ID from a half token and destroy it at the same time. If the user doesn't exist, 0 is returned.
func GetMemberGuilds ¶
func GetMemberGuilds(ctx context.Context, hostname string, memberID uint64) (guilds []string, err error)
GetMemberGuilds returns a list of guilds that the member is in.
func HasOwner ¶
HasOwner is used to check if the server has an owner. THIS IS VERY SLOW AND SHOULD ONLY BE RAN DURING SETUP! It intentionally doesn't return an error because errors are picked up later in setup.
func InternallyAddTask ¶
InternallyAddTask is used to add a task in a very low level way to the database. You likely want the scheduler package for this. The task ID is returned.
func InternallyConsumeConfig ¶
func InternallyConsumeConfig(handler func(key string, value json.RawMessage)) error
InternallyConsumeConfig is used to getting the config and handling events relating to it. This will block until the config is initially fetched, but will spin off as a side effect logic to auto-update it. The handler SHOULD be okay with concurrency. Note you probably do not want this function, but instead functions exposed in the config package.
func InternallyDeleteAllUserIDTokens ¶
InternallyDeleteAllUserIDTokens is used to delete all tokens for a user ID. Returns the deletion job ID's.
func InternallyDeleteToken ¶
InternallyDeleteToken is used to internally delete a token. This is used by the token delete job. Returns the deletion job ID and any errors.
func InternallyGetTokenJobID ¶
InternallyGetTokenJobID is used to get the job ID of a token. This is used by the token extend job.
func PublishGenericEvent ¶
PublishGenericEvent is used to publish a generic event.
func ScanUserFromToken ¶
ScanUserFromToken is used to scan a user from a token.
func SetupKey ¶
SetupKey makes the setup key and returns it. Returns an existing key if it was already edited.
func UpdateConfig ¶
UpdateConfig is used to write a key to the database and also dispatch events for it. Blocks until events are done.
Types ¶
type CreatePasswordUserError ¶
type CreatePasswordUserError struct {
// contains filtered or unexported fields
}
CreatePasswordUserError is used to define an error thrown by CreatePasswordUser.
func (CreatePasswordUserError) Error ¶
func (p CreatePasswordUserError) Error() string
Error implements the error interface.
func (CreatePasswordUserError) POValue ¶
func (p CreatePasswordUserError) POValue() string
POValue is used to get the PO value of the error.
func (CreatePasswordUserError) Unwrap ¶
func (p CreatePasswordUserError) Unwrap() error
Unwrap returns the underlying error.
type Task ¶
type Task struct { // TaskID is the ID of the task. This is ignored by InternallyAddTask. TaskID string // JobHandler is the job handler in charge of running this task. JobHandler string // JobBody is the msgpack body of the job. JobBody []byte // SchedulerMetadata is the msgpack metadata for the scheduler. SchedulerMetadata []byte }
Task is used to define an item in the database tasks table.
func DeleteAndReturnNTasks ¶
DeleteAndReturnNTasks is used to delete N number of tasks from the DB which are ready to be processed with the supported jobs of this worker and then deletes them from the database.