vbdb

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2019 License: Apache-2.0 Imports: 10 Imported by: 3

README

vbdb

Package to provide easy access to vikebot databases from go source code.

Build Status codecov Go Report Card GoDoc

Dependency diagram

Dependency diagram

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveRoundentries

func ActiveRoundentries(userID int) (roundentries []vbcore.Roundentry, success bool)

ActiveRoundentries is the same as `ActiveRoundentriesCtx` but uses the `defaultCtx` as logger.

func ActiveRoundentriesCtx

func ActiveRoundentriesCtx(userID int, ctx *zap.Logger) (roundentries []vbcore.Roundentry, success bool)

ActiveRoundentriesCtx returns all Roundentries from a user, for games which are currently of status `vbcore.RoundStatusOpen`, `vbcore.RoundStatusClosed` or `vbcore.RoundStatusRunning`. Doesn't returns Roundentries for already finished games (e.g. `vbcore.RoundStatusFinished`).

func ActiveRounds

func ActiveRounds() (lobbies []vbcore.Round, success bool)

ActiveRounds is the same as `ActiveRoundsCtx` but uses the `defaultCtx` as logger.

func ActiveRoundsCtx

func ActiveRoundsCtx(ctx *zap.Logger) (rounds []vbcore.Round, success bool)

ActiveRoundsCtx loads all rounds which have not status `vbcore.RoundStatusFinished`.

func CountGames

func CountGames() int

CountGames is the same as `CountGamesCtx` but uses the `defaultCtx` as logger.

func CountGamesCtx

func CountGamesCtx(ctx *zap.Logger) int

CountGamesCtx adds up all existing roundentries. Example: There are three rounds in the database and all were joined by 20 players. Therefore `3 x 20 = 60` will be returned.

func CountUsers

func CountUsers() int

CountUsers is the same as `CountUsersCtx` but uses the `defaultCtx` as logger.

func CountUsersCtx

func CountUsersCtx(ctx *zap.Logger) int

CountUsersCtx adds up the amount of all registered users

func ExistsMessage

func ExistsMessage(id int64) (exists bool, err error)

ExistsMessage checks wheter the id (and therefore) it's associated value exist or not.

func Init

func Init(config *Config, logCtx *zap.Logger) (err error)

Init initializes all internally used structures of vbdb. E.g. a database connection pool is created and connections get established. If any errors occur durring initialization the error will be returned. The passed zap instance is saved and used as default throughout the package if no explicit logging-context is provided

func InsertMessage

func InsertMessage(msg string) (id int64, err error)

InsertMessage inserts the passed string into the msg table and returns the auto-incremented id (foreign-key in other tables).

func JoinRound

func JoinRound(userID, roundID int) (alreadyJoined, success bool)

JoinRound is the same as `JoinRoundCtx` but uses the `defaultCtx` as logger.

func JoinRoundCtx

func JoinRoundCtx(userID, roundID int, ctx *zap.Logger) (alreadyJoined, success bool)

JoinRoundCtx lets the user join the specified round. The first return value `alreadyJoined` indicates if the user has already joined the team and the call is redundent.

func JoinedUsers

func JoinedUsers(roundID int) (joined []int, success bool)

JoinedUsers is the same as `JoinedUsersCtx` but uses the `defaultCtx` as logger.

func JoinedUsersCtx

func JoinedUsersCtx(roundID int, ctx *zap.Logger) (joined []int, success bool)

JoinedUsersCtx returns the `userID`s of all users which joined the round specified through the roundID.

func JwtAdd

func JwtAdd(jti string, exp time.Time, userID int, iat time.Time, ip string) (success bool)

JwtAdd is the same as `JwtAddCtx` but uses the `defaultCtx` as logger.

func JwtAddCtx

func JwtAddCtx(jti string, exp time.Time, userID int, iat time.Time, ip string, ctx *zap.Logger) (success bool)

JwtAddCtx adds the passed `jti` (JWT ID), `exp` and `userID` into the `jwts` table as valid entries. Can later be modified to invalid (e.g. blacklisted)

func JwtIsBlacklisted

func JwtIsBlacklisted(jti string) (blacklisted bool, success bool)

JwtIsBlacklisted is the same as `JwtIsBlacklistedCtx` but uses the `defaultCtx` as logger.

func JwtIsBlacklistedCtx

func JwtIsBlacklistedCtx(jti string, ctx *zap.Logger) (blacklisted bool, success bool)

JwtIsBlacklistedCtx checks whether the passed `jti` (JWT ID) is already blacklisted or not

func OAuthExists

func OAuthExists(providerID string, provider string) (userID int, exists bool, success bool)

OAuthExists is the same as `OAuthExistsCtx` but uses the `defaultCtx` as logger.

func OAuthExistsCtx

func OAuthExistsCtx(providerID string, provider string, ctx *zap.Logger) (userID int, exists bool, success bool)

OAuthExistsCtx checks if the `providerID` is already registered with the specified `provider`. If so the associated `userID` (from vikebot) is returned.

func RegcodeFromUserID

func RegcodeFromUserID(userID int) (code string, finished bool, success bool)

RegcodeFromUserID is the same as `RegcodeFromUserIDCtx` but uses the `defaultCtx` as logger.

func RegcodeFromUserIDCtx

func RegcodeFromUserIDCtx(userID int, ctx *zap.Logger) (code string, finished bool, success bool)

RegcodeFromUserIDCtx exchanged a `userID` to it's associated registration code and a `finished` state (indicating the state of the registration).

func RegisterOauthGithub

func RegisterOauthGithub(user *github.User) (userID int, code string, success bool)

RegisterOauthGithub is the same as `RegisterOauthGithubCtx` but uses the `defaultCtx` as logger.

func RegisterOauthGithubCtx

func RegisterOauthGithubCtx(u *github.User, ctx *zap.Logger) (userID int, code string, success bool)

RegisterOauthGithubCtx maps the `*github.User` instance to a `vbcore.User` and passes it to `RegisterUserCtx`.

func RegisterOauthGoogle

func RegisterOauthGoogle(user *vbcore.GoogleUser) (userID int, code string, success bool)

RegisterOauthGoogle is the same as `RegisterOauthGoogleCtx` but uses the `defaultCtx` as logger.

func RegisterOauthGoogleCtx

func RegisterOauthGoogleCtx(u *vbcore.GoogleUser, ctx *zap.Logger) (userID int, code string, success bool)

RegisterOauthGoogleCtx maps the `*vbcore.GoogleUser` instance to a `vbcore.User` and passes it to `RegisterUserCtx`.

func RegisterUser

func RegisterUser(user vbcore.User, msg string) (userID int, regCode string, success bool)

RegisterUser is the same as `RegisterUserCtx` but uses the `defaultCtx` as logger.

func RegisterUserCtx

func RegisterUserCtx(user vbcore.User, msg string, ctx *zap.Logger) (userID int, regCode string, success bool)

RegisterUserCtx registers a new user and returns the user's ID, the msgID used for all inserts and a registration code (which the user must use in order to register later).

func RoundExists

func RoundExists(roundID int) (exists, success bool)

RoundExists is the same as `RoundExistsCtx` but uses the `defaultCtx` as logger.

func RoundExistsCtx

func RoundExistsCtx(roundID int, ctx *zap.Logger) (exists, success bool)

RoundExistsCtx checks whether a round specified by it's ID exists or not

func RoundentryConnectinfo

func RoundentryConnectinfo(authtoken string) (connectinfo *vbcore.RoundentryConnectinfo, exists bool, success bool)

RoundentryConnectinfo is the same as `RoundentryConnectinfoCtx` but uses the `defaultCtx` as logger.

func RoundentryConnectinfoCtx

func RoundentryConnectinfoCtx(authtoken string, ctx *zap.Logger) (connectinfo *vbcore.RoundentryConnectinfo, exists bool, success bool)

RoundentryConnectinfoCtx returns everything needed to connect to the `vbgs` instance hosting the game associated with the `authtoken`.

func RoundentryFromRoundticket

func RoundentryFromRoundticket(roundticket string) (verification *vbcore.RoundentryVerification, exists bool, success bool)

RoundentryFromRoundticket is the same as `RoundentryFromRoundticketCtx` but uses the `defaultCtx` as logger.

func RoundentryFromRoundticketCtx

func RoundentryFromRoundticketCtx(roundticket string, ctx *zap.Logger) (verification *vbcore.RoundentryVerification, exists bool, success bool)

RoundentryFromRoundticketCtx verifies that a user passed `roundticket` exists in the database. If so informations about the specific `roundentry` are returned so further verifications can be performed.

func RoundentryFromWatchtoken

func RoundentryFromWatchtoken(watchtoken string) (verification *vbcore.RoundentryVerification, exists bool, success bool)

RoundentryFromWatchtoken is the same as `RoundentryFromWatchtokenCtx` but uses the `defaultCtx` as logger.

func RoundentryFromWatchtokenCtx

func RoundentryFromWatchtokenCtx(watchtoken string, ctx *zap.Logger) (verification *vbcore.RoundentryVerification, exists bool, success bool)

RoundentryFromWatchtokenCtx verifies that a user passed `watchtoken` exists in the database. If so informations about the specific `roundentry` are returned so further verifications can be performed.

func SelectMessage

func SelectMessage(id int64) (msg string, exists bool, err error)

SelectMessage receives the message associated to the passed id.

func SelectMessageExists

func SelectMessageExists(id int64) (msg *string, err error)

SelectMessageExists checks whether the id (and therefore) it's associated value exists or not and if so also returns the value. If the id doesn't exists the msg pointer will be nil.

func UpdateUser

func UpdateUser(newUser *vbcore.User, oldUser *vbcore.SafeUser, msg string) (success bool)

UpdateUser is the same as `UpdateUserCtx` but uses the `defaultCtx` as logger.

func UpdateUserCtx

func UpdateUserCtx(newUser *vbcore.User, oldUser *vbcore.SafeUser, msg string, ctx *zap.Logger) (success bool)

UpdateUserCtx compares a newUser with an oldUser and updates the differences into the database. The msg parameter is used to safe some kind of log message how this update come about. This func uses SQL-transactions, hence the complete update process only failes or succeeds - nothing in between.

func UpdateUserEmailStatus

func UpdateUserEmailStatus(userID int, email string, status int) (success bool)

func UpdateUserEmailStatusCtx

func UpdateUserEmailStatusCtx(userID int, email string, status int, ctx *zap.Logger) (success bool)

func UserDeleteSocialExpectCtx

func UserDeleteSocialExpectCtx(userID int, social []string, ctx *zap.Logger) (success bool)

func UserDeleteWebExpectCtx

func UserDeleteWebExpectCtx(userID int, web []string, ctx *zap.Logger) (success bool)

func UserEmailVerificationIsCtx

func UserEmailVerificationIsCtx(userID int, email string, verificationCode string, ctx *zap.Logger) (verified bool, success bool)

func UserEmailVerificationLoadCtx

func UserEmailVerificationLoadCtx(userID int, email string, ctx *zap.Logger) (lastSent *time.Time, valid bool, succes bool)

func UserEmailVerificationSetCtx

func UserEmailVerificationSetCtx(userID int, email string, verificationCode string, ctx *zap.Logger) (success bool)

func UserFromID

func UserFromID(userID int) (user *vbcore.SafeUser, success bool)

UserFromID is the same as `UserFromIDCtx` but uses the `defaultCtx` as logger.

func UserFromIDCtx

func UserFromIDCtx(userID int, ctx *zap.Logger) (user *vbcore.SafeUser, success bool)

UserFromIDCtx loads the user associated with the given `userID`. Returns `nil` if the user isn't found.

func UserFromUsername

func UserFromUsername(username string, ctx *zap.Logger) (user *vbcore.SafeUser, success bool)

UserFromUsername is the same as `UserFromUsernameCtx` but uses the `defaultCtx` as logger.

func UserFromUsernameCtx

func UserFromUsernameCtx(username string, ctx *zap.Logger) (user *vbcore.SafeUser, success bool)

UserFromUsernameCtx loads the user associated with the given `username`. Returns `nil` if the user isn't found.

func UserIDFromRegcode

func UserIDFromRegcode(code string) (userID int, finished bool, success bool)

UserIDFromRegcode is the same as `UserIDFromRegcodeCtx` but uses the `defaultCtx` as logger.

func UserIDFromRegcodeCtx

func UserIDFromRegcodeCtx(code string, ctx *zap.Logger) (userID int, finished bool, success bool)

UserIDFromRegcodeCtx exchanges a registration code for a `userID` and a `finished` state (indicating the state of the registration).

func UserIDFromUsername

func UserIDFromUsername(username string) (userID int, exists bool, success bool)

UserIDFromUsername is the same as `UserIDFromUsernameCtx` but uses the `defaultCtx` as logger.

func UserIDFromUsernameCtx

func UserIDFromUsernameCtx(username string, ctx *zap.Logger) (userID int, exists bool, success bool)

UserIDFromUsernameCtx tries to find the user which currently uses th passed username. Comparisons are made with lower-case strings

func UserPermission

func UserPermission(userID int) (permission int, success bool)

UserPermission is the same as `UserPermissionCtx` but uses the `defaultCtx` as logger.

func UserPermissionCtx

func UserPermissionCtx(userID int, ctx *zap.Logger) (permission int, success bool)

UserPermissionCtx loads the current permission of the specified user from the database. It is mandatory that the user corresponding to the passed ID does exists!

func UserSetRegistrationDoneCtx

func UserSetRegistrationDoneCtx(userID int, ctx *zap.Logger) (success bool)

func UsernameFromID added in v0.1.2

func UsernameFromID(userID int) (username string, success bool)

UsernameFromID returns a username as string from an given ID

func UsernameFromIDCtx added in v0.1.2

func UsernameFromIDCtx(userID int, ctx *zap.Logger) (username string, success bool)

UsernameFromIDCtx loads the username associated with the given `userID`. Returns "" (empty string) if the user isn't found.

func UsernamesFromRoundID added in v0.1.2

func UsernamesFromRoundID(roundID int) (usernames map[int]string, success bool)

UsernamesFromRoundID returns usernames as a slice of string from an given roundID

func UsernamesFromRoundIDCtx added in v0.1.2

func UsernamesFromRoundIDCtx(roundID int, ctx *zap.Logger) (usernames map[int]string, success bool)

UsernamesFromRoundIDCtx loads the usernames associated with the given `roundID`. Returns an empty slice if the roundID isn't valid.

func WebsocketAddressFromWatchtokenCtx

func WebsocketAddressFromWatchtokenCtx(watchtoken string, ctx *zap.Logger) (websocket string, exists, success bool)

WebsocketAddressFromWatchtokenCtx resolves a watchtoken to it's associated gameserver's websocket address.

Types

type Config

type Config struct {
	DbAddr *vbcore.Endpoint
	DbUser string
	DbPass string
	DbName string
}

Config collects all relevant informations/credentials to access a vikebot database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL