Documentation
¶
Index ¶
- func CreateURL(url *URL)
- func UpdateURL(url *URL) error
- type Book
- type File
- type ToDo
- type URL
- type User
- func (user *User) BeforeSave(tx *gorm.DB) error
- func (user *User) CheckPassword(providedPassword string) error
- func (user *User) CreateUserRecord() error
- func (user *User) HashPassword(password string) error
- func (user *User) Prepare()
- func (u *User) SaveUser() (*User, error)
- func (user *User) Validate(action string) map[string]string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Book ¶
type Book struct { gorm.Model // gorm.Model provides the fields ID, CreatedAt, UpdatedAt, and DeletedAt Title string `gorm:"size:191;not null;unique" json:"title"` Author string `gorm:"size:191;not null" json:"author"` Publisher string `gorm:"size:191;not null" json:"publisher"` Description string `gorm:"size:191;not null" json:"description"` }
Book is a struct that represents a book in the database
type File ¶
type File struct { gorm.Model // GORM model that contains the ID, CreatedAt, UpdatedAt, and DeletedAt fields Filename string `gorm:"not null"` // Filename of the file. Cannot be null. UUID string `gorm:"unique;not null"` // UUID of the file. Must be unique and cannot be null. }
File is a struct that represents a file in the database
type ToDo ¶
type ToDo struct { gorm.Model Title string `gorm:"size:100;not null;unique" json:"title"` Content string `gorm:"text;not null" json:"content"` Author User `json:"author"` AuthorID uint `gorm:"not null" json:"author_id"` }
ToDo is a struct contains information about a to-do item
func (*ToDo) DeleteAToDo ¶
DeleteAToDo is a method that deletes a ToDo struct from the database It takes a pointer to a gorm.DB as an argument and returns the number of rows affected
func (*ToDo) FindUserToDos ¶
FindUserToDos is a method that finds all ToDo structs for a given user It takes a pointer to a gorm.DB and a user ID as arguments and returns a pointer to a slice of ToDo structs
func (*ToDo) Prepare ¶
func (t *ToDo) Prepare()
Prepare is a method that prepares the ToDo struct for saving It escapes the title and content strings and sets the created and updated times
func (*ToDo) SaveToDo ¶
SaveToDo is a method that saves a ToDo struct to the database It takes a pointer to a gorm.DB as an argument and returns a pointer to the saved ToDo struct
func (*ToDo) UpdateAToDo ¶
UpdateAToDo is a method that updates a ToDo struct in the database It takes a pointer to a gorm.DB as an argument and returns a pointer to the updated ToDo struct
type URL ¶
type URL struct { gorm.Model LongURL string `json:"long_url" gorm:"unique"` ShortURL string `json:"short_url" gorm:"unique"` AccessCount uint `json:"access_count"` LastAccessed *time.Time `json:"last_accessed"` AccessPlace string `json:"access_place"` }
URL is a struct that stores the information for a URL
func GetURLByShortURL ¶
GetURLByShortURL is a method used to get a URL from the database by its short URL It takes a string as a parameter and returns a URL struct and an error
func (*URL) GenerateShortURL ¶
func (u *URL) GenerateShortURL()
GenerateShortURL is a method used to generate a random short URL It takes no parameters and returns nothing
type User ¶
type User struct { gorm.Model Name string `json:"name" binding:"required"` Email string `json:"email" binding:"required,email" gorm:"unique"` Password string `json:"password" binding:"required"` }
User defines the user in db User struct is used to store user information in the database
func (*User) BeforeSave ¶
BeforeSave is a hook that is called before a user is saved to the database It hashes the user's password before saving it to the database
func (*User) CheckPassword ¶
CheckPassword checks user password CheckPassword takes a string as a parameter and compares it to the user's encrypted password It returns an error if there is an issue comparing the passwords
func (*User) CreateUserRecord ¶
CreateUserRecord creates a user record in the database CreateUserRecord takes a pointer to a User struct and creates a user record in the database It returns an error if there is an issue creating the user record
func (*User) HashPassword ¶
HashPassword encrypts user password HashPassword takes a string as a parameter and encrypts it using bcrypt It returns an error if there is an issue encrypting the password
func (*User) Prepare ¶
func (user *User) Prepare()
Prepare is a function that is called before a user is saved to the database It escapes any HTML characters and trims any whitespace