models

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClipCount

func ClipCount(db *sql.DB, userID int64) (count int64, err error)

ClipCount returns the number of clips for a user. Returns -1 if the user doesn't exist or has 0 clips.

func CloseConnection

func CloseConnection(db *sql.DB)

CloseConnection closes the connection to the database. Use defer CloseConnection below CreateConnection.

func CreateConnection

func CreateConnection() (db *sql.DB, err error)

CreateConnection creates a connection to the database. Add CloseConnection in the next line.

func DeleteClips

func DeleteClips(db *sql.DB, userID int64) (err error)

DeleteClips deletes all the clips of a user.

func GetPasswordHash

func GetPasswordHash(db *sql.DB, username string) (hash string, err error)

GetPasswordHash fetches the hash from the database.

func GetUserID

func GetUserID(db *sql.DB, username string) (userID int64, err error)

GetUserID searches a user in DB by its userID. Uses username internally.

func InsertClip

func InsertClip(db *sql.DB, c Data) (clipID int64, err error)

InsertClip inserts a clip into the database and returns clipid.

func InsertPasswordHash

func InsertPasswordHash(db *sql.DB, username, hashPassword string) (err error)

InsertPasswordHash inserts the password hash in the database.

func InsertUser

func InsertUser(db *sql.DB, username string) (userID int64, err error)

InsertUser inserts a new user into the database and returns a userID. userID is -1 if it already exists.

func SelectByUsername

func SelectByUsername(db *sql.DB, username string) (userID int64, err error)

SelectByUsername searches a user in DB by its username.

Types

type Data

type Data struct {
	UserID    int64  `json:"userID"`
	Username  string `json:"username"`
	MessageID int64  `json:"clipID"`
	Message   string `json:"message" binding:"required"`
	Secret    *bool  `json:"secret" binding:"required"`
}

Data is the data structure for clip data. This is used for storing and retrieving clips.

func SelectClip

func SelectClip(db *sql.DB, clipID, userID int64) (c Data, err error)

SelectClip returns clip Data for a given user.

type Users

type Users struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password"  binding:"required"`
	PCount   int    `json:"pCount"  binding:"required"`
	SPCount  int    `json:"spCount"  binding:"required"`
}

Users is the data structure for user data. This is used for authentication. It has addational fields such as PasswordCount- Pcount & SaltedPasswordCount- SPcount. These are used to check if the password has been changed or not

Jump to

Keyboard shortcuts

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