model

package
v0.0.0-...-1cbb4d5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPasswordUnmatch = errors.New("password unmatch")

ErrPasswordUnmatch is error for password unmatch when logging in.

Functions

func ArticlesDeleteAll

func ArticlesDeleteAll(tx *sql.Tx) (sql.Result, error)

ArticlesDeleteAll deltes all articles. Useful for testing.

func Salt

func Salt(n int) string

Salt returns random salt string.

func Stretch

func Stretch(password, salt string) string

Stretch makes stretched password using salt.

func UserExists

func UserExists(db *sql.DB, email string) (bool, error)

UserExists check if user is exists by given email.

Types

type Article

type Article struct {
	ID      int64     `json:"article_id"`
	Title   string    `json:"title"`
	Body    string    `json:"body"`
	UserID  int64     `json:"user_id"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

Article returns model object for article.

func ArticleOne

func ArticleOne(db *sql.DB, id int64) (Article, error)

ArticleOne returns the article for given id.

func ArticlesAll

func ArticlesAll(db *sql.DB) ([]Article, error)

ArticlesAll returns all articles.

func ScanArticle

func ScanArticle(r *sql.Row) (Article, error)

func ScanArticles

func ScanArticles(rs *sql.Rows) ([]Article, error)

func (*Article) Delete

func (t *Article) Delete(tx *sql.Tx) (sql.Result, error)

Delete deletes article by given id.

func (*Article) Insert

func (t *Article) Insert(tx *sql.Tx) (sql.Result, error)

Insert inserts new article.

func (*Article) Update

func (t *Article) Update(tx *sql.Tx) (sql.Result, error)

Update updates article by given article.

type ArticleUser

type ArticleUser struct {
	ID       int64     `json:"article_id"`
	Title    string    `json:"title"`
	Body     string    `json:"body"`
	UserID   int64     `json:"user_id"`
	Created  time.Time `json:"created"`
	Updated  time.Time `json:"updated"`
	UserName string    `json:"user_name"`
}

ArticleUser includes writer information who wrote it.

func ArticleUserOne

func ArticleUserOne(db *sql.DB, id int64) (ArticleUser, error)

func ScanArticleUser

func ScanArticleUser(r *sql.Row) (ArticleUser, error)

func ScanArticleUsers

func ScanArticleUsers(rs *sql.Rows) ([]ArticleUser, error)

type User

type User struct {
	ID      int64     `json:"user_id"`
	Name    string    `json:"name"`
	Email   string    `json:"email"`
	Salt    string    `json:"salt"`
	Salted  string    `json:"salted"`
	Created time.Time `json:"created"`
	Updated time.Time `json:"updated"`
}

User returns model object for user.

func Auth

func Auth(db *sql.DB, email, password string) (User, error)

Auth makes user authentication.

func ScanUser

func ScanUser(r *sql.Row) (User, error)

func ScanUsers

func ScanUsers(rs *sql.Rows) ([]User, error)

func UserByEmail

func UserByEmail(db *sql.DB, email string) (User, error)

UserByEmail fetch user by email. Email is unique key.

func UserOne

func UserOne(db *sql.DB, id int64) (User, error)

UserOne returns the user for given id

func (*User) Insert

func (u *User) Insert(tx *sql.Tx, password string) (sql.Result, error)

Insert inserts new user.

func (*User) Update

func (u *User) Update(tx *sql.Tx) (sql.Result, error)

Update updates user by given user.

Jump to

Keyboard shortcuts

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