package pagemodel import ( "gitee.com/leijmdas/gobase/goconfig/common/base/basedto" "gitee.com/leijmdas/gobase/goconfig/common/base/baseiface" "gitee.com/leijmdas/gobase/goconfig/common/base/jsonutils" "reflect" ) func FromResult[T baseiface.IpoolObj](result *basedto.IchubResult) *IchubResult[T] { var ichubResult = NewIchubResult[T]() return ichubResult.From(result) } type IchubResult[T any] struct { *basedto.IchubResult Data T `json:"data"` Total int `json:"total"` } func DefaultIchubResult[T any]() *IchubResult[T] { return NewIchubResult[T]() } func NewIchubResult[T any]() *IchubResult[T] { var i = &IchubResult[T]{ IchubResult: basedto.NewIchubResult(), } i.InitProxy(i) return i } func (self *IchubResult[T]) NewOfPtrType() T { var ptr T var objType = reflect.TypeOf(ptr) var value = reflect.New(objType.Elem()) var entity = value.Interface().(T) return entity } func (self *IchubResult[T]) From(result *basedto.IchubResult) *IchubResult[T] { self.IchubResult = result self.Data = self.NewOfPtrType() jsonutils.FromJson(jsonutils.ToJsonPretty(result.Data), self.Data) return self } func (self *IchubResult[T]) SuccessData(data T) *IchubResult[T] { self.Code = 200 self.Msg = "成功" self.Data = data return self } func (self *IchubResult[T]) FailMsg(msg string) *IchubResult[T] { self.Code = 500 self.Msg = msg return self } func (self *IchubResult[T]) ToString() string { return jsonutils.ToJsonPretty(self) } func (self *IchubResult[T]) String() string { return jsonutils.ToJsonPretty(self) }
package pagemodel import ( "gitee.com/leijmdas/gobase/goconfig/common/base/baseiface" "gitee.com/leijmdas/gobase/goconfig/common/base/baseutils" "gitee.com/leijmdas/gobase/goconfig/common/base/jsonutils" "gitee.com/leijmdas/goweb/commonpage/page" "gitee.com/leijmdas/goweb/commonpage/pagees" ) func FromPageResult[T baseiface.IpoolObj](result *page.PageResult) *PageResult[T] { var pageResult = NewPageResult[T]() return pageResult.ValueOfPageResult(result) } func FromPageEsResult[T baseiface.IpoolObj](result *pagees.PageEsResult) *PageResult[T] { var pageResult = NewPageResult[T]() return pageResult.ValueOf(result) } type PageResult[T any] struct { *page.PageResult Data []T `json:"data"` } func DefaultResult[T any]() *PageResult[T] { return NewPageResult[T]() } func NewPageResult[T any]() *PageResult[T] { var pr = &PageResult[T]{ PageResult: page.DefaultResult(), } pr.PageResult.InitProxy(pr) //pr.IchubClientDto.InitProxy(pr) return pr } func (self *PageResult[T]) ValueOf(result *pagees.PageEsResult) *PageResult[T]{ self.PageSize = result.PageSize self.PageCurrent = result.PageCurrent self.Total = result.Total var records []T = make([]T, 0) if result.IsSuccess() { jsonutils.FromJson(jsonutils.ToJsonPretty(result.Data), &records) self.Data = records } return self } func (self *PageResult[T]) ValueOfPageResult(result *page.PageResult) *PageResult[T] { self.PageSize = result.PageSize self.PageCurrent = result.PageCurrent self.Total = result.Total var records []T = make([]T, 0) if result.IsSuccess() { jsonutils.FromJson(jsonutils.ToJsonPretty(result.Data), &records) self.Data = records for _, record := range self.Data { baseutils.IfProxy(record) } } return self } func (self *PageResult[T]) Single() bool { return false }标签:return,IchubResult,self,接口,go,result,func,泛型,PageResult From: https://blog.csdn.net/leijmdas/article/details/142315761