models

package
v0.0.0-...-d6488ed Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUser

func AddUser(username, password, email string) error

func ConnectToDB

func ConnectToDB() *gorm.DB

func GeneratePassword

func GeneratePassword(pwd string) string

func GetPostsByUserID

func GetPostsByUserID(id int) (*[]Post, error)

func SetDB

func SetDB(database *gorm.DB)

Types

type Post

type Post struct {
	ID        int `gorm:"primary_key"`
	UserID    int
	User      User
	Body      string     `gorm:"type:varchar(180)"`
	Timestamp *time.Time `sql:"DEFAULT:current_timestamp"`
}

type User

type User struct {
	ID           int    `gorm:"primary_key"`
	Username     string `gorm:"type:varchar(64)"`
	Email        string `gorm:"type:varchar(120)"`
	PasswordHash string `gorm:"type:varchar(128)"`
	Posts        []Post
	Followers    []*User `gorm:"many2many:follower;association_jointable_foreignkey:follower_id"`
}

func GetUserByUsername

func GetUserByUsername(username string) (User, error)

func (*User) SetPassword

func (u *User) SetPassword(password string)

Jump to

Keyboard shortcuts

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