package service import ( "SciencesServer/serve/es" "encoding/json" ) type Manage struct { ID uint64 `json:"id"` // ID Identity int `json:"identity"` // 身份信息 Title string `json:"title"` // 名称 Keyword string `json:"keyword"` // 关键词 Research string `json:"research"` // 研究方向 } type ManageOption func(manage *Manage) func (c *Manage) Index() string { return "es_manage_index" } func (this *Manage) Create() error { _bytes, _ := json.Marshal(this) return es.Create(this.Index(), _bytes) } func (this *Manage) Search(page, pageSize int, condition map[string]interface{}) (interface{}, error) { return es.Search(this, this.Index(), condition, page, pageSize) } func WithManageID(id uint64) ManageOption { return func(manage *Manage) { manage.ID = id } } func WithManageTitle(title string) ManageOption { return func(manage *Manage) { manage.Title = title } } func WithManageKeyword(keyword string) ManageOption { return func(manage *Manage) { manage.Keyword = keyword } } func WithManageResearch(research string) ManageOption { return func(manage *Manage) { manage.Research = research } } func NewManage(options ...ManageOption) *Manage { out := new(Manage) for _, option := range options { option(out) } return out }