model

package
v0.0.0-...-ab77271 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package model contains all Model structures and helpers which are permanently stored by a store.Store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePostID

func GeneratePostID(createdAt time.Time, comment, subject string) string

GeneratePostID creates a new post ID based on the post's subject, comment and creation time

func HashPassword

func HashPassword(password string) []byte

HashPassword hashes a password using bcrypt with default cost.

func Validate

func Validate(v interface{}) error

Validate validates a struct based on a validator tags

Types

type Ban

type Ban struct {
	ID string `json:"id" bson:"_id"`

	IP        string        `json:"ip" bson:"ip"`
	CreatedAt time.Time     `json:"createdAt" bson:"createdAt"`
	Duration  time.Duration `json:"duration" bson:"duration"`
	Reason    string        `json:"reason" bson:"reason"`
	Mod       string        `json:"mod" bson:"mod"`
}

Ban is a user's ban

type Board

type Board struct {
	URI         string    `json:"uri" bson:"_id" validate:"board"`
	Name        string    `json:"title" validate:"required"`
	Description string    `json:"description,omitempty"`
	CreatedAt   time.Time `json:"createdAt" bson:"createdAt"`
	Hidden      bool      `json:"hidden,omitempty" bson:"hidden"`
}

Board is a board

func NewBoard

func NewBoard(uri, name, description string) *Board

NewBoard creates a new board

func (*Board) Valid

func (board *Board) Valid() error

Valid returns an error if the board is invalid

type Media

type Media struct {
	MIME string `json:"mime" bson:"MIME"`
	Name string `json:"name" bson:"name"`
	Size int64  `json:"size" bson:"size"`

	Storage            string `json:"-" bson:"storage"`
	StorageID          string `json:"-" bson:"storageId"`
	ThumbnailStorageID string `json:"-" bson:"thumbStorageId"`

	URL          string `json:"url" bson:"url"`
	ThumbnailURL string `json:"thumbnailUrl" bson:"thumbnailUrl"`
}

Media is a comment's media

type Post

type Post struct {
	ID     string `json:"id" bson:"_id" validate:"required"`
	Parent string `json:"parent,omitempty" bson:"parent,omitempty"`
	Board  string `json:"board,omitempty" bson:"board,omitempty" validate:"board,required"`

	Name    string `json:"name" bson:"name" validate:"max=16"`
	Comment string `json:"comment" bson:"comment" validate:"required,min=4,max=5120"`
	Subject string `json:"subject,omitempty" bson:"subject,omitempty" validate:"max=48"`
	Deleted bool   `json:"deleted,omitempty" bson:"deleted"`
	IP      string `json:"address,omitempty" bson:"address"`

	Locked bool `json:"locked,omitempty" bson:"locked"`
	Hidden bool `json:"hidden,omitempty" hidden:"locked"`

	Medias []*Media `json:"medias" bson:"medias"`

	CreatedAt    time.Time  `json:"createdAt" bson:"createdAt"`
	LastBumpedAt *time.Time `json:"lastBumpedAt,omitempty" bson:"lastBumpedAt"`
}

Post is a comment

func NewPost

func NewPost(parent, board, name, subject, comment, ip string) *Post

NewPost creates a new post

func (*Post) IsReply

func (p *Post) IsReply() bool

IsReply returns whether a post is a reply or not

func (*Post) Valid

func (p *Post) Valid() error

Valid returns an error if the post is invalid

type Thread

type Thread struct {
	Post    `json:",inline" bson:",inline"`
	Replies []*Post `json:"replies" bson:"replies"`
}

Thread is a structure holding a collection of posts, where one of them is the common parent (OP) and the others are replies

type User

type User struct {
	Username       string    `json:"username" bson:"_id" validate:"required,min=4,max=32"`
	Role           string    `json:"role" bson:"role" validate:"required"`
	HashedPassword []byte    `json:"-" bson:"hashedPassword" validate:"required"`
	CreatedAt      time.Time `json:"createdAt" bson:"createdAt"`
	LastModifiedAt time.Time `json:"modifiedAt" bson:"modifiedAt"`
}

User is a user

func NewUser

func NewUser(username, password, role string) *User

NewUser creates a new user

func (*User) SetPassword

func (u *User) SetPassword(password string)

SetPassword sets an user password after hashing it.

func (*User) Valid

func (u *User) Valid() error

Valid returns an error if the user is invalid

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) bool

VerifyPassword verifies if a user has the correct password

Jump to

Keyboard shortcuts

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