Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrUserNotFound = New(gorm.ErrRecordNotFound, "user not found")
)
View Source
var UserFieldJsonMap = map[string]string{
"Email": "email",
"FirstName": "firstname",
"LastName": "lastname",
"Password": "password",
}
UserFieldJsonMap represents user's struct field for json key
Functions ¶
func GetValidate ¶
func GetValidate() *validator.Validate
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents errors for user packages whilst maintaining base error. Error can either be checked using == or by calling errors.Is() to check the base of Error.
Example of User not found in database.
user, err := s.UserByEmail(tt.args.email) if err != nil { if err == ErrUserNotFound { // omitted } //or if errors.Is(err, gorm.ErrRecordNotFound) { // omitted } }
type Store ¶
type Store interface { // Create inserts a new user into the database. // Returns an error if the user could not be created. Create(u *User) error // User gets a user from the database that matches the specified criteria. // Returns the user and any error that occurred. User(u *User) (*User, error) // UserByID gets a user from the database with the specified ID. // Returns the user and any error that occurred. UserByID(id uint) (*User, error) // UserByEmail gets a user from the database with the specified email address. // Returns the user and any error that occurred. UserByEmail(email string) (*User, error) // UserByName gets users from the database with the specified name. // Returns the users and any error that occurred. UserByName(name string) ([]*User, error) // DB gets the underlying *gorm.DB instance. DB() *gorm.DB // SetDB sets the underlying *gorm.DB instance. SetDB(db *gorm.DB) // Migrate auto-migrates the User model to database. Migrate() error }
type User ¶
type User struct { ID uint `gorm:"primarykey"` UUID string `json:"uuid" gorm:"index:uuid_index,unique"` Email string `json:"email" gorm:"index:email_index,unique" validate:"required,email"` FirstName string `json:"firstname" validate:"required,min=3"` LastName string `json:"lastname" validate:"required,min=3"` Password string `json:"-" validate:"required,min=5"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index"` }
Click to show internal directories.
Click to hide internal directories.