Documentation ¶
Index ¶
- type Field
- type Pagination
- type Resource
- func (r *Resource) Create(v interface{}) error
- func (r *Resource) CreateX(v interface{}) error
- func (r *Resource) Delete(pk interface{}) error
- func (r *Resource) Detail(pk interface{}, v interface{}) error
- func (r *Resource) List(slice interface{}, args ...interface{}) (int64, error)
- func (r *Resource) ListPage(slice interface{}, page *Pagination, args ...interface{}) (int64, error)
- func (r *Resource) Model() *gorm.DB
- func (r *Resource) Row(pk interface{}) *gorm.DB
- func (r *Resource) Update(pk interface{}, v interface{}) error
- func (r *Resource) UpdateX(pk interface{}, v interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pagination ¶
type Resource ¶
type Resource struct { Fields []*Field // contains filtered or unexported fields }
func NewGormResource ¶
NewGormResource 实例化资源
example:
type Article struct { ID int64 `resource:"pk;search:=;order:desc" json:"id"` Title string `resource:"create;update;search:like" json:"title"` Content string `resource:"create;update;search:like" json:"text"` Status byte `resource:"search:=" json:"-"` } r := NewGormResource(db, &Article{})
func (*Resource) Create ¶
Create 创建资源,支持传入 struct、map,创建前会重置 resource tag 未设置 create 的字段为0值,使得创建记录时忽略值
err := r.Create(&Article{Title: "Hello", Status: 2}) 这里 status 会被重置为 0 ,因为 status 的 resource tag 未设置 create
func (*Resource) CreateX ¶
CreateX 创建资源,支持传入 struct、map,传入的值均有效
err := r.CreateX(&Article{Title: "Hello", Status: 2}) 这里 status 成功设置值
func (*Resource) List ¶
List 查询资源列表,提供查询条件,排序规则,查询列表,查询规则会以resource tag 的search 值为准
list := []*Article{} total, err := r.List(&list, map[string]byte{"status": 1})
func (*Resource) ListPage ¶
func (r *Resource) ListPage(slice interface{}, page *Pagination, args ...interface{}) (int64, error)
Click to show internal directories.
Click to hide internal directories.