Documentation
¶
Index ¶
- func GetConnection() *sqlx.DB
- func GetDatabase() *sqlx.DB
- func GetSQLConnection() *sql.DB
- func GetSQLDatabase() *sql.DB
- type JwtClaims
- type JwtRefreshTokenClaims
- type Log
- type LogCollection
- func (logCollection *LogCollection) Add(log *Log) (uint64, error)
- func (logCollection *LogCollection) ByLanguage(language enums.Language)
- func (logCollection *LogCollection) Delete(log *Log) error
- func (logCollection *LogCollection) Get(id uint64) (*Log, error)
- func (logCollection *LogCollection) GetAll() error
- func (logCollection *LogCollection) GetAllFromUser(userID uint64) error
- func (logCollection *LogCollection) GetAllWithFilters(filters map[string]interface{}) error
- func (logCollection *LogCollection) Length() int
- func (logCollection *LogCollection) Update(log *Log) error
- type Preferences
- type RefreshToken
- type RefreshTokenCollection
- func (refreshTokenCollection *RefreshTokenCollection) Add(refreshToken *RefreshToken) (uint64, error)
- func (refreshTokenCollection *RefreshTokenCollection) Get(id uint64) (*RefreshToken, error)
- func (refreshTokenCollection *RefreshTokenCollection) GetByClaims(claims *JwtRefreshTokenClaims) (*RefreshToken, error)
- func (refreshTokenCollection *RefreshTokenCollection) Length() int
- type User
- type UserCollection
- func (userCollection *UserCollection) Add(user *User) (uint64, error)
- func (userCollection *UserCollection) Get(id uint64) (*User, error)
- func (userCollection *UserCollection) GetAll() error
- func (userCollection *UserCollection) GetAuthenticationData(email string) (*User, error)
- func (userCollection *UserCollection) Length() int
- func (userCollection *UserCollection) Update(user *User) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConnection ¶
GetConnection Returns database connection without a database
func GetSQLConnection ¶
GetSQLConnection Returns database connection without a database with the default sql package
func GetSQLDatabase ¶
GetSQLDatabase Returns database connection from pool with the default sql package
Types ¶
type JwtClaims ¶
type JwtClaims struct {
User *User `json:"user"`
RefreshTokenID uint64 `json:"refresh_token_id"`
jwt.StandardClaims
}
JwtClaims json web token claim
type JwtRefreshTokenClaims ¶
type JwtRefreshTokenClaims struct {
UserID uint64 `json:"user_id" db:"user_id"`
DeviceID string `json:"device_id" db:"device_id"`
jwt.StandardClaims
}
JwtRefreshTokenClaims json web token claim for refresh token
type Log ¶
type Log struct {
ID uint64 `json:"id" db:"id"`
UserID uint64 `json:"user_id" db:"user_id"`
Language enums.Language `json:"language" db:"language"`
Date string `json:"date" db:"date"`
Duration uint64 `json:"duration" db:"duration"`
Activity enums.Activity `json:"activity" db:"activity"`
Notes types.JSONText `json:"notes" db:"notes"`
}
Log model
type LogCollection ¶
type LogCollection struct {
Logs []Log `json:"logs"`
}
LogCollection array of logs
func (*LogCollection) Add ¶
func (logCollection *LogCollection) Add(log *Log) (uint64, error)
Add a log to the database
func (*LogCollection) ByLanguage ¶
func (logCollection *LogCollection) ByLanguage(language enums.Language)
ByLanguage only keeps the logs for a certain language
func (*LogCollection) Delete ¶
func (logCollection *LogCollection) Delete(log *Log) error
Delete a log
func (*LogCollection) Get ¶
func (logCollection *LogCollection) Get(id uint64) (*Log, error)
Get a log by id
func (*LogCollection) GetAll ¶
func (logCollection *LogCollection) GetAll() error
GetAll returns all logs
func (*LogCollection) GetAllFromUser ¶
func (logCollection *LogCollection) GetAllFromUser(userID uint64) error
GetAllFromUser returns all logs from a certain user
func (*LogCollection) GetAllWithFilters ¶
func (logCollection *LogCollection) GetAllWithFilters(filters map[string]interface{}) error
GetAllWithFilters returns all logs with filters applied
func (*LogCollection) Length ¶
func (logCollection *LogCollection) Length() int
Length returns the amount of logs in the collection
func (*LogCollection) Update ¶
func (logCollection *LogCollection) Update(log *Log) error
Update a log
type Preferences ¶
type Preferences struct {
Languages []enums.Language `json:"languages" db:"languages"`
PublicProfile bool `json:"public_profile" db:"public_profile"`
}
Preferences model
func (*Preferences) Scan ¶
func (preferences *Preferences) Scan(src interface{}) error
Scan of preferences (support for embedded preferences)
type RefreshToken ¶
type RefreshToken struct {
ID uint64 `json:"id" db:"id"`
UserID uint64 `json:"user_id" db:"user_id"`
DeviceID string `json:"device_id" db:"device_id"`
RefreshToken string `json:"refresh_token" db:"refresh_token"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
InvalidatedAt pq.NullTime `json:"invalidated_at" db:"invalidated_at"`
}
RefreshToken model
func (*RefreshToken) GenerateRefreshToken ¶
func (refreshToken *RefreshToken) GenerateRefreshToken() error
func (*RefreshToken) GenerateRefreshTokenString ¶
func (refreshToken *RefreshToken) GenerateRefreshTokenString() (string, error)
GenerateRefreshToken generates a new refresh token that's valid for one year for a given user and device and returns the signed JWT token
func (*RefreshToken) Validate ¶
func (refreshToken *RefreshToken) Validate() error
Validate the RefreshToken model
type RefreshTokenCollection ¶
type RefreshTokenCollection struct {
RefreshTokens []RefreshToken `json:"refresh_tokens"`
}
RefreshTokenCollection array of refresh tokens
func (*RefreshTokenCollection) Add ¶
func (refreshTokenCollection *RefreshTokenCollection) Add(refreshToken *RefreshToken) (uint64, error)
Add a refresh token to the database
func (*RefreshTokenCollection) Get ¶
func (refreshTokenCollection *RefreshTokenCollection) Get(id uint64) (*RefreshToken, error)
Get a refresh token by id
func (*RefreshTokenCollection) GetByClaims ¶
func (refreshTokenCollection *RefreshTokenCollection) GetByClaims(claims *JwtRefreshTokenClaims) (*RefreshToken, error)
Get a refresh token by claims nil is returned when a token is invalidated
func (*RefreshTokenCollection) Length ¶
func (refreshTokenCollection *RefreshTokenCollection) Length() int
Length returns the amount of refresh tokens in the collection
type User ¶
type User struct {
ID uint64 `json:"id" db:"id"`
Email string `json:"email" db:"email"`
DisplayName string `json:"display_name" db:"display_name"`
Password string `json:"password" db:"password"`
Role enums.Role `json:"role" db:"role"`
Preferences Preferences `json:"preferences" db:"preferences"`
}
User model
func (*User) HashPassword ¶
HashPassword hash the currently set password
type UserCollection ¶
type UserCollection struct {
Users []User `json:"users"`
}
UserCollection array of users
func (*UserCollection) Add ¶
func (userCollection *UserCollection) Add(user *User) (uint64, error)
Add a user to the database
func (*UserCollection) Get ¶
func (userCollection *UserCollection) Get(id uint64) (*User, error)
Get a user by id
func (*UserCollection) GetAll ¶
func (userCollection *UserCollection) GetAll() error
GetAll returns all users
func (*UserCollection) GetAuthenticationData ¶
func (userCollection *UserCollection) GetAuthenticationData(email string) (*User, error)
GetAuthenticationData get data needed to generate jwt token
func (*UserCollection) Length ¶
func (userCollection *UserCollection) Length() int
Length returns the amount of users in the collection
func (*UserCollection) Update ¶
func (userCollection *UserCollection) Update(user *User) error
Update a user