代码拉取完成,页面将自动刷新
package book
import (
"dario.cat/mergo"
"github.com/go-playground/validator/v10"
"gitee.com/talk-about-articles/keyauth-tz/common/page"
pb_request "gitee.com/talk-about-articles/keyauth-tz/common/request"
"github.com/rs/xid"
"net/http"
"time"
)
const (
AppName = "book"
)
var (
validate = validator.New()
)
func NewCreateBookRequest() *CreateBookRequest {
return &CreateBookRequest{}
}
func NewBook(req *CreateBookRequest) (*Book, error) {
if err := req.Validate(); err != nil {
return nil, err
}
return &Book{
Id: xid.New().String(),
CreateAt: time.Now().UnixMicro(),
Data: req,
}, nil
}
func (req *CreateBookRequest) Validate() error {
return validate.Struct(req)
}
func NewBookSet() *BookSet {
return &BookSet{
Items: []*Book{},
}
}
func (s *BookSet) Add(item *Book) {
s.Items = append(s.Items, item)
}
func NewDefaultBook() *Book {
return &Book{
Data: &CreateBookRequest{},
}
}
func (i *Book) Update(req *UpdateBookRequest) {
i.UpdateAt = time.Now().UnixMicro()
i.UpdateBy = req.UpdateBy
i.Data = req.Data
}
func (i *Book) Patch(req *UpdateBookRequest) error {
i.UpdateAt = time.Now().UnixMicro()
i.UpdateBy = req.UpdateBy
return mergo.MergeWithOverwrite(i.Data, req.Data)
}
func NewDescribeBookRequest(id string) *DescribeBookRequest {
return &DescribeBookRequest{
Id: id,
}
}
func NewQueryBookRequest() *QueryBookRequest {
return &QueryBookRequest{
Page: page.NewDefaultPageRequest(),
}
}
func NewQueryBookRequestFromHTTP(r *http.Request) *QueryBookRequest {
qs := r.URL.Query()
return &QueryBookRequest{
Page: page.NewPageRequestFromHTTP(r),
Keywords: qs.Get("keywords"),
}
}
func NewPutBookRequest(id string) *UpdateBookRequest {
return &UpdateBookRequest{
Id: id,
UpdateMode: pb_request.UpdateMode_PUT,
UpdateAt: time.Now().UnixMicro(),
Data: NewCreateBookRequest(),
}
}
func NewPatchBookRequest(id string) *UpdateBookRequest {
return &UpdateBookRequest{
Id: id,
UpdateMode: pb_request.UpdateMode_PATCH,
UpdateAt: time.Now().UnixMicro(),
Data: NewCreateBookRequest(),
}
}
func NewDeleteBookRequestWithID(id string) *DeleteBookRequest {
return &DeleteBookRequest{
Id: id,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。