Documentation ¶
Index ¶
- Variables
- func Login(username string, password string) (string, error)
- func Migrate() *gorm.DB
- type Noise
- type NoiseFile
- type Tag
- type User
- func (user *User) Delete() error
- func (user *User) DeletePermanently() error
- func (user *User) GetNoise(id string) (Noise, error)
- func (user *User) GetNoiseWithFile(id string) (Noise, error)
- func (user *User) GetNoises(q string, sort string, take int) ([]Noise, error)
- func (user *User) Logout(token string) error
- func (user *User) NoiseCreate(title string, file []byte, ts []string) (Noise, error)
Constants ¶
This section is empty.
Variables ¶
var DB *gorm.DB
DB and R variables is exported to use on the whole models package. The connections is set by using drivers on the main package.
var RPOOL *redis.Pool
RPOOL variables keeps a pool to get connection when need to access Redis.
Functions ¶
Types ¶
type Noise ¶
type Noise struct { gorm.Model Title string `gorm:"not null"` Author User `gorm:"foreignkey:AuthorRefer" json:"-"` AuthorRefer uint `gorm:"not null" json:"-"` Tags []Tag `gorm:"many2many:noise_tags"` File NoiseFile `gorm:"foreignkey:NoiseRefer;association_foreignkey:ID" json:"-"` Text string IsActive bool `gorm:"default:false"` }
Noise model.
func (*Noise) AfterSave ¶
AfterCreate runs starting to recognition and returns. Recognition ops are run as a goroutine.
func (*Noise) DeletePermanently ¶
DeletePermanently deletes the noise permanently.
type NoiseFile ¶
type NoiseFile struct { gorm.Model Data []byte `gorm:"not null"` // TODO move file to gcloud. Noise *Noise `gorm:"foreignkey:NoiseRefer"` NoiseRefer uint `gorm:"not null"` }
NoiseFile model.
type Tag ¶
type Tag struct { gorm.Model Title string `gorm:"not null"` Author User `gorm:"foreignkey:AuthorRefer" json:"-"` AuthorRefer uint `gorm:"not null" json:"-"` Noises []Noise `gorm:"many2many:noise_tags" json:"-"` }
Tag model.
type User ¶
type User struct { gorm.Model Name string `gorm:"not null"` Surname string `gorm:"not null"` Username string `gorm:"unique;unique_index;not null"` Password []byte `gorm:"not null" json:"-"` Noises []Noise `gorm:"foreignkey:AuthorRefer;association_foreignkey:ID" json:"-"` Tags []Tag `gorm:"foreignkey:AuthorRefer;association_foreignkey:ID" json:"-"` }
User model.
func CurrentUser ¶
CurrentUser returns the current user that matches with the token.
func SignUp ¶
SignUp creates users by using username and password. Password is hashed by using bcrypt package.
func (*User) DeletePermanently ¶
DeletePermanently deletes the user.
func (*User) GetNoiseWithFile ¶
GetNoiseWithFile returns wanted noise's file that is associated with the user.
func (*User) GetNoises ¶
GetNoises returns all noises that are matched by checking noises' titles, noises' texts and tags' titles. It can set sort type and limit.