model

package
v0.0.0-...-35786f1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArticleGenerator

func ArticleGenerator() interface{}

ArticleGenerator generator function for the Article model.

Be careful, this generator doesn't set the AuthorID!

Generate articles using the following:

database.NewFactory(model.ArticleGenerator).Generate(5)

func RateLimiterFunc

func RateLimiterFunc(request *goyave.Request) ratelimiter.Config

RateLimiterFunc returns rate limiting configuration Anonymous users have a quota of 50 requests per minute while authenticated users are limited to 500 requests per minute.

func UserGenerator

func UserGenerator() interface{}

UserGenerator generator function for the User model. Generate users using the following:

database.NewFactory(model.UserGenerator).Generate(5)

Types

type Article

type Article struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	Title     string `gorm:"type:char(200);not null"`
	Contents  string `gorm:"type:text;not null"`
	Slug      string `gorm:"type:char(80);not null;unique;uniqueIndex"`
	AuthorID  uint   `json:"-"`
	Author    *User  `gorm:"constraint:OnDelete:CASCADE;" json:",omitempty"`
}

Article represents an article posted by a user.

func (*Article) BeforeCreate

func (a *Article) BeforeCreate(tx *gorm.DB) error

BeforeCreate hook executed before a Article record is inserted in the database. Ensures the slug is up to date.

func (*Article) BeforeUpdate

func (a *Article) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate hook executed before an Article record is updated in the database. Ensures the slug is up to date.

type User

type User struct {
	ID        uint `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	Username  string      `gorm:"type:char(100);unique;uniqueIndex;not null"`
	Email     string      `gorm:"type:char(100);unique;uniqueIndex;not null" auth:"username"`
	Image     null.String `gorm:"type:char(100);default:null" json:"-"`
	Password  string      `gorm:"type:char(60);not null" auth:"password" json:"-"`
}

User represents a user.

func (*User) BeforeCreate

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

BeforeCreate hook executed before a User record is inserted in the database. Ensures the password is encrypted using bcrypt, with the cost defined by the config entry "app.bcryptCost".

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate hook executed before a User record is updated in the database. Ensures the password is encrypted using bcrypt, with the cost defined by the config entry "app.bcryptCost".

Jump to

Keyboard shortcuts

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