datamodels

package
v12.2.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: BSD-3-Clause Imports: 2 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePassword

func GeneratePassword(userPassword string) ([]byte, error)

GeneratePassword will generate a hashed password for us based on the user's input.

func ValidatePassword

func ValidatePassword(userPassword string, hashed []byte) (bool, error)

ValidatePassword will check if passwords are matched.

Types

type User

type User struct {
	ID             int64     `json:"id" form:"id"`
	Firstname      string    `json:"firstname" form:"firstname"`
	Username       string    `json:"username" form:"username"`
	HashedPassword []byte    `json:"-" form:"-"`
	CreatedAt      time.Time `json:"created_at" form:"created_at"`
}

User is our User example model. Keep note that the tags for public-use (for our web app) should be kept in other file like "web/viewmodels/user.go" which could wrap by embedding the datamodels.User or define completely new fields instead but for the sake of the example, we will use this datamodel as the only one User model in our application.

func (User) IsValid

func (u User) IsValid() bool

IsValid can do some very very simple "low-level" data validations.

Jump to

Keyboard shortcuts

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