models

package
v0.0.0-...-126ed2c Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Product

type Product struct {
	ID    uint   `gorm:"primarykey" json:"id"`
	Name  string `json:"name"`
	Price int    `json:"price"`
	Timestamps
}

func (Product) TableName

func (Product) TableName() string

type Timestamps

type Timestamps struct {
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (*Timestamps) BeforeCreate

func (t *Timestamps) BeforeCreate(tx *gorm.DB) (err error)

func (*Timestamps) BeforeUpdate

func (t *Timestamps) BeforeUpdate(tx *gorm.DB) (err error)

type User

type User struct {
	ID       uint   `gorm:"primaryKey" json:"id"`
	Username string `gorm:"unique;not null" json:"username"`
	Password string `gorm:"not null" json:"-"`
	Timestamps
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate adalah hook yang akan dijalankan sebelum data pengguna baru disimpan ke database

func (*User) CheckPassword

func (u *User) CheckPassword(password string) error

CheckPassword memeriksa apakah password yang diberikan cocok dengan password yang di-hash

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword mengenkripsi password pengguna menggunakan bcrypt

func (User) TableName

func (User) TableName() string

Jump to

Keyboard shortcuts

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