models

package
Version: v0.0.0-...-11f4b66 Latest Latest
Warning

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

Go to latest
Published: May 19, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB_DRIVER = "mysql"
)

Variables

View Source
var (
	// RedisPool
	RedisPool *redis.Pool
)

Functions

func AddCategory

func AddCategory(m *Category) (id int64, err error)

AddCategory insert a new Category into database and returns last inserted Id on success.

func AddLabel

func AddLabel(m *Label) (id int64, err error)

AddLabel insert a new Label into database and returns last inserted Id on success.

func AddTopic

func AddTopic(m *Topic) (id int64, err error)

AddTopic insert a new Topic into database and returns last inserted Id on success.

func CheckToken

func CheckToken(token string) bool

校验token是否有效

func DeleteCategory

func DeleteCategory(id int) (err error)

DeleteCategory deletes Category by Id and returns error if the record to be deleted doesn't exist

func DeleteLabel

func DeleteLabel(id int) (err error)

DeleteLabel deletes Label by Id and returns error if the record to be deleted doesn't exist

func DeleteTopic

func DeleteTopic(id int) (err error)

DeleteTopic deletes Topic by Id and returns error if the record to be deleted doesn't exist

func GenToken

func GenToken() string

func GetAllCategory

func GetAllCategory(query map[string]string, fields []string, sortby []string, order []string,
	offset int64, limit int64) (ml []interface{}, err error)

GetAllCategory retrieves all Category matches certain condition. Returns empty list if no records exist

func GetAllLabel

func GetAllLabel(query map[string]string, fields []string, sortby []string, order []string,
	offset int64, limit int64) (ml []interface{}, err error)

GetAllLabel retrieves all Label matches certain condition. Returns empty list if no records exist

func GetKey

func GetKey(key string) string

GetKey get value from redis by key

func InitRedisPool

func InitRedisPool()

InitRedisPool init redis

func RegisterDB

func RegisterDB()

func SetKey

func SetKey(key string, value interface{})

SetKey set key value into redis

func UpdateCategoryById

func UpdateCategoryById(m *Category) (err error)

UpdateCategory updates Category by Id and returns error if the record to be updated doesn't exist

func UpdateLabelById

func UpdateLabelById(m *Label) (err error)

UpdateLabel updates Label by Id and returns error if the record to be updated doesn't exist

func UpdateTopicByID

func UpdateTopicByID(m *Topic) (err error)

UpdateTopic updates Topic by Id and returns error if the record to be updated doesn't exist

Types

type Admin

type Admin struct {
	Name     string `json:"username"`
	Password string `json:"password"`
}

type Category

type Category struct {
	Id          int      `json:"id"  orm:"column(id);auto"`
	Name        string   `json:"name" orm:"column(name);size(100)"`
	Description string   `json:"desc" orm:"column(description);size(500)"`
	Topics      []*Topic `json:"-" orm:"reverse(many)"`
}

func GetCategoryById

func GetCategoryById(id int) (v *Category, err error)

GetCategoryById retrieves Category by Id. Returns error if Id doesn't exist

func (*Category) TableName

func (t *Category) TableName() string

type CommResult

type CommResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func NewCommResult

func NewCommResult() *CommResult

type Label

type Label struct {
	Id          int      `json:"id"  orm:"column(id);auto"`
	Name        string   `json:"name"  orm:"column(name);size(100)"`
	Description string   `json:"desc"  orm:"column(description);size(500)"`
	Topics      []*Topic `json:"-" orm:"reverse(many)"`
}

func GetLabelById

func GetLabelById(id int) (v *Label, err error)

GetLabelById retrieves Label by Id. Returns error if Id doesn't exist

func (*Label) TableName

func (t *Label) TableName() string

type LoginResult

type LoginResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		User  Admin  `json:"user"`
		Token string `json:"token"`
		Name  string `json:"name"`
		UUId  string `json:"uuid"`
	} `json:"data"`
}

type Topic

type Topic struct {
	Id              int       `json:"id" orm:"column(id);auto"`
	Uid             int64     `json:"uid" orm:"column(uid)"`
	Title           string    `json:"title" orm:"column(title);size(255)"`
	Content         string    `json:"content" orm:"column(content);type(text)"`
	Summary         string    `json:"summary" orm:"column(summary);size(200)"`
	Attachment      string    `json:"url" orm:"column(attachment);size(255)"`
	Category        *Category `json:"cate" orm:"rel(fk);on_delete(do_nothing)"`
	Labels          []*Label  `json:"labels" orm:"rel(m2m)"`
	Created         time.Time `orm:"auto_now_add;column(created);type(datetime)"`
	Updated         time.Time `json:"-" orm:"auto_now;column(updated);type(datetime)"`
	Deleted         time.Time `json:"-" orm:"auto_now;column(deleted);type(datetime)"`
	Views           int64     `json:"views" orm:"column(views)"`
	Author          string    `json:"author" orm:"column(author);size(255)"`
	ReplyTime       time.Time `json:"-" orm:"column(reply_time);type(datetime);null"`
	ReplyCount      int64     `json:"reply_count" orm:"column(reply_count)"`
	ReplyLastUserId int64     `json:"reply_last_user_id" orm:"column(reply_last_user_id)"`
}

topic info

func FastFind

func FastFind(vagueName string) ([]*Topic, error)

func GetAllTopics

func GetAllTopics(query map[string]string, fields []string, sortby []string, order []string,
	offset int64, limit int64) ([]*Topic, error)

GetAllTopics retrieves all Topic matches certain condition. Returns empty list if no records exist

func GetTopicByID

func GetTopicByID(id int) (v *Topic, err error)

GetTopicByID retrieves Topic by Id. Returns error if Id doesn't exist

func GetTopicsByCateID

func GetTopicsByCateID(cateId int) ([]*Topic, error)

GetTopicsByCateID retrieves Topics by Category

func GetTopicsByLabelID

func GetTopicsByLabelID(tagId int) ([]*Topic, error)

GetTopicsByTagId retrieves Topics by Label

func (*Topic) TableName

func (t *Topic) TableName() string

type TopicsResult

type TopicsResult struct {
	Code   int      `json:"code"`
	Msg    string   `json:"msg"`
	Topics []*Topic `json:"topics"`
}

Jump to

Keyboard shortcuts

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