Merge remote-tracking branch 'origin/master'

This commit is contained in:
火线兔
2023-09-15 10:18:45 +08:00
2 changed files with 13 additions and 10 deletions

View File

@@ -11,10 +11,13 @@ import (
//type Map t.MapStringT
// Data ...
type Data map[string]interface{}
//type Data map[string]interface{}
// Ret Yes. this is what you think, but still under testing
type Data[T int64 | float64 | string | any] map[string]T
//Paginate
type Paginate struct {
type Paginate[T int64 | float64 | string | any] struct {
Total int64 `json:"total",gorose:"total" :"total"`
PerPage int `json:"per_page",gorose:"per_page" :"per_page"`
CurrentPage int `json:"current_page",gorose:"current_page" :"current_page"`
@@ -23,7 +26,7 @@ type Paginate struct {
LastPageUrl int `json:"last_page_url",gorose:"last_page_url" :"last_page_url"`
NextPageUrl interface{} `json:"next_page_url",gorose:"next_page_url" :"next_page_url"`
PrevPageUrl interface{} `json:"prev_page_url",gorose:"prev_page_url" :"prev_page_url"`
Data []Data `json:"data",gorose:"data" :"data"`
Data []Data[T] `json:"data",gorose:"data" :"data"`
}
// BindType ...
@@ -66,7 +69,7 @@ func (b BindType) String() string {
}
// Binder ...
type Binder struct {
type Binder[T int64 | float64 | string | any] struct {
// Bind是指传入的对象 [slice]map,[slice]struct
// 传入的原始对象
BindOrigin interface{}
@@ -85,14 +88,14 @@ type Binder struct {
BindLimit int
BindPrefix string
// 多条map结果,传入的是string table时
BindAll []Data
BindAll []Data[T]
}
var _ IBinder = &Binder{}
var _ IBinder = &Binder[t.Type]{}
// NewBinder ...
func NewBinder(o ...interface{}) *Binder {
var binder = new(Binder)
func NewBinder[T int64 | float64 | string | any](o ...interface{}) *Binder[T] {
var binder = new(Binder[T])
if len(o) > 0 {
binder.SetBindOrigin(o[0])
} else {
@@ -102,7 +105,7 @@ func NewBinder(o ...interface{}) *Binder {
}
// BindParse ...
func (o *Binder) BindParse(prefix string) error {
func (o *Binder[T]) BindParse(prefix string) error {
if o.GetBindOrigin() == nil {
return nil
}

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/tobycroft/gorose-pro
go 1.16
go 1.18
require (
github.com/gohouse/golib v0.0.0-20210711163732-a5c22059eb75