This commit is contained in:
John Guo 2023-02-08 19:08:10 +08:00 committed by GitHub
parent d66af122c7
commit 117fc6eda2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 197 additions and 102 deletions

View File

@ -173,28 +173,28 @@ func (a *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array {
return a
}
// InsertBefore inserts the `value` to the front of `index`.
func (a *Array) InsertBefore(index int, value interface{}) error {
// InsertBefore inserts the `values` to the front of `index`.
func (a *Array) InsertBefore(index int, values ...interface{}) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]interface{}{}, a.array[index:]...)
a.array = append(a.array[0:index], value)
a.array = append(a.array[0:index], values...)
a.array = append(a.array, rear...)
return nil
}
// InsertAfter inserts the `value` to the back of `index`.
func (a *Array) InsertAfter(index int, value interface{}) error {
// InsertAfter inserts the `values` to the back of `index`.
func (a *Array) InsertAfter(index int, values ...interface{}) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]interface{}{}, a.array[index+1:]...)
a.array = append(a.array[0:index+1], value)
a.array = append(a.array[0:index+1], values...)
a.array = append(a.array, rear...)
return nil
}

View File

@ -168,28 +168,28 @@ func (a *IntArray) SortFunc(less func(v1, v2 int) bool) *IntArray {
return a
}
// InsertBefore inserts the `value` to the front of `index`.
func (a *IntArray) InsertBefore(index int, value int) error {
// InsertBefore inserts the `values` to the front of `index`.
func (a *IntArray) InsertBefore(index int, values ...int) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]int{}, a.array[index:]...)
a.array = append(a.array[0:index], value)
a.array = append(a.array[0:index], values...)
a.array = append(a.array, rear...)
return nil
}
// InsertAfter inserts the `value` to the back of `index`.
func (a *IntArray) InsertAfter(index int, value int) error {
func (a *IntArray) InsertAfter(index int, values ...int) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]int{}, a.array[index+1:]...)
a.array = append(a.array[0:index+1], value)
a.array = append(a.array[0:index+1], values...)
a.array = append(a.array, rear...)
return nil
}

View File

@ -155,28 +155,28 @@ func (a *StrArray) SortFunc(less func(v1, v2 string) bool) *StrArray {
return a
}
// InsertBefore inserts the `value` to the front of `index`.
func (a *StrArray) InsertBefore(index int, value string) error {
// InsertBefore inserts the `values` to the front of `index`.
func (a *StrArray) InsertBefore(index int, values ...string) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]string{}, a.array[index:]...)
a.array = append(a.array[0:index], value)
a.array = append(a.array[0:index], values...)
a.array = append(a.array, rear...)
return nil
}
// InsertAfter inserts the `value` to the back of `index`.
func (a *StrArray) InsertAfter(index int, value string) error {
// InsertAfter inserts the `values` to the back of `index`.
func (a *StrArray) InsertAfter(index int, values ...string) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
}
rear := append([]string{}, a.array[index+1:]...)
a.array = append(a.array[0:index+1], value)
a.array = append(a.array[0:index+1], values...)
a.array = append(a.array, rear...)
return nil
}

View File

@ -21,6 +21,7 @@ import (
"github.com/gogf/gf/v2/util/guid"
)
// https://github.com/gogf/gf/issues/1934
func Test_Issue1934(t *testing.T) {
table := createInitTable()
defer dropTable(table)
@ -460,11 +461,12 @@ func Test_Issue2105(t *testing.T) {
// https://github.com/gogf/gf/issues/2231
func Test_Issue2231(t *testing.T) {
linkPattern := `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)`
link := `mysql:root:12345678@tcp(127.0.0.1:3306)/a正bc式?loc=Local&parseTime=true`
var (
pattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)`
link = `mysql:root:12345678@tcp(127.0.0.1:3306)/a正bc式?loc=Local&parseTime=true`
)
gtest.C(t, func(t *gtest.T) {
match, err := gregex.MatchString(linkPattern, link)
match, err := gregex.MatchString(pattern, link)
t.AssertNil(err)
t.Assert(match[1], "mysql")
t.Assert(match[2], "root")
@ -476,6 +478,26 @@ func Test_Issue2231(t *testing.T) {
})
}
// https://github.com/gogf/gf/issues/2339
func Test_Issue2339(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
model1 := db.Model(table, "u1").Where("id between ? and ?", 1, 9)
model2 := db.Model("? as u2", model1)
model3 := db.Model("? as u3", model2)
all2, err := model2.WhereGT("id", 6).OrderAsc("id").All()
t.AssertNil(err)
t.Assert(len(all2), 3)
t.Assert(all2[0]["id"], 7)
all3, err := model3.WhereGT("id", 7).OrderAsc("id").All()
t.AssertNil(err)
t.Assert(len(all3), 2)
t.Assert(all3[0]["id"], 8)
})
}
// https://github.com/gogf/gf/issues/2356
func Test_Issue2356(t *testing.T) {
gtest.C(t, func(t *gtest.T) {

View File

@ -563,16 +563,16 @@ func formatWhereHolder(ctx context.Context, db DB, in formatWhereHolderInput) (n
if i >= len(in.Args) {
break
}
// ===============================================================
// Sub query, which is always used along with a string condition.
if model, ok := in.Args[i].(*Model); ok {
// ===============================================================
if subModel, ok := in.Args[i].(*Model); ok {
index := -1
whereStr, _ = gregex.ReplaceStringFunc(`(\?)`, whereStr, func(s string) string {
index++
if i+len(newArgs) == index {
sqlWithHolder, holderArgs := model.getFormattedSqlAndArgs(
ctx, queryTypeNormal, false,
)
newArgs = append(newArgs, holderArgs...)
sqlWithHolder, holderArgs := subModel.getHolderAndArgsAsSubModel(ctx)
in.Args = gutil.SliceInsertAfter(in.Args, i, holderArgs...)
// Automatically adding the brackets.
return "(" + sqlWithHolder + ")"
}

View File

@ -497,7 +497,9 @@ func (m *Model) doGetAllBySql(ctx context.Context, queryType queryType, sql stri
return
}
func (m *Model) getFormattedSqlAndArgs(ctx context.Context, queryType queryType, limit1 bool) (sqlWithHolder string, holderArgs []interface{}) {
func (m *Model) getFormattedSqlAndArgs(
ctx context.Context, queryType queryType, limit1 bool,
) (sqlWithHolder string, holderArgs []interface{}) {
switch queryType {
case queryTypeCount:
queryFields := "COUNT(1)"
@ -539,6 +541,14 @@ func (m *Model) getFormattedSqlAndArgs(ctx context.Context, queryType queryType,
}
}
func (m *Model) getHolderAndArgsAsSubModel(ctx context.Context) (holder string, args []interface{}) {
holder, args = m.getFormattedSqlAndArgs(
ctx, queryTypeNormal, false,
)
args = m.mergeArguments(args)
return
}
func (m *Model) getAutoPrefix() string {
autoPrefix := ""
if gstr.Contains(m.tables, " JOIN ") {

View File

@ -13,7 +13,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
func Example_transaction() {
func ExampleTransaction() {
g.DB().Transaction(context.TODO(), func(ctx context.Context, tx gdb.TX) error {
// user
result, err := tx.Insert("user", g.Map{

View File

@ -12,7 +12,7 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
)
func Example_conversionNormalFormats() {
func ExampleConversionNormalFormats() {
data :=
`{
"users" : {

View File

@ -14,7 +14,7 @@ import (
"github.com/gogf/gf/v2/os/glog"
)
func Example_cronAddSingleton() {
func ExampleCronAddSingleton() {
gcron.AddSingleton(ctx, "* * * * * *", func(ctx context.Context) {
glog.Print(context.TODO(), "doing")
time.Sleep(2 * time.Second)

View File

@ -12,7 +12,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
func Example_context() {
func ExampleContext() {
ctx := context.WithValue(context.Background(), "Trace-Id", "123456789")
g.Log().Error(ctx, "runtime error")

View File

@ -14,7 +14,7 @@ import (
"github.com/gogf/gf/v2/os/gtimer"
)
func Example_add() {
func ExampleAdd() {
var (
ctx = context.Background()
now = time.Now()

View File

@ -14,28 +14,52 @@ import (
// SliceCopy does a shallow copy of slice `data` for most commonly used slice type
// []interface{}.
func SliceCopy(data []interface{}) []interface{} {
newData := make([]interface{}, len(data))
copy(newData, data)
return newData
func SliceCopy(slice []interface{}) []interface{} {
newSlice := make([]interface{}, len(slice))
copy(newSlice, slice)
return newSlice
}
// SliceInsertBefore inserts the `values` to the front of `index` and returns a new slice.
func SliceInsertBefore(slice []interface{}, index int, values ...interface{}) (newSlice []interface{}) {
if index < 0 || index >= len(slice) {
return slice
}
newSlice = make([]interface{}, len(slice)+len(values))
copy(newSlice, slice[0:index])
copy(newSlice[index:], values)
copy(newSlice[index+len(values):], slice[index:])
return
}
// SliceInsertAfter inserts the `values` to the back of `index` and returns a new slice.
func SliceInsertAfter(slice []interface{}, index int, values ...interface{}) (newSlice []interface{}) {
if index < 0 || index >= len(slice) {
return slice
}
newSlice = make([]interface{}, len(slice)+len(values))
copy(newSlice, slice[0:index+1])
copy(newSlice[index+1:], values)
copy(newSlice[index+1+len(values):], slice[index+1:])
return
}
// SliceDelete deletes an element at `index` and returns the new slice.
// It does nothing if the given `index` is invalid.
func SliceDelete(data []interface{}, index int) (newSlice []interface{}) {
if index < 0 || index >= len(data) {
return data
func SliceDelete(slice []interface{}, index int) (newSlice []interface{}) {
if index < 0 || index >= len(slice) {
return slice
}
// Determine array boundaries when deleting to improve deletion efficiency.
if index == 0 {
return data[1:]
} else if index == len(data)-1 {
return data[:index]
return slice[1:]
} else if index == len(slice)-1 {
return slice[:index]
}
// If it is a non-boundary delete,
// it will involve the creation of an array,
// then the deletion is less efficient.
return append(data[:index], data[index+1:]...)
return append(slice[:index], slice[index+1:]...)
}
// SliceToMap converts slice type variable `slice` to `map[string]interface{}`.

View File

@ -0,0 +1,39 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gutil_test
import (
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gutil"
)
func ExampleSliceInsertBefore() {
s1 := g.Slice{
0, 1, 2, 3, 4,
}
s2 := gutil.SliceInsertBefore(s1, 1, 8, 9)
fmt.Println(s1)
fmt.Println(s2)
// Output:
// [0 1 2 3 4]
// [0 8 9 1 2 3 4]
}
func ExampleSliceInsertAfter() {
s1 := g.Slice{
0, 1, 2, 3, 4,
}
s2 := gutil.SliceInsertAfter(s1, 1, 8, 9)
fmt.Println(s1)
fmt.Println(s2)
// Output:
// [0 1 2 3 4]
// [0 1 8 9 2 3 4]
}

View File

@ -14,7 +14,7 @@ import (
"github.com/gogf/gf/v2/text/gstr"
)
func Example_Rule_Required() {
func ExampleRule_Required() {
type BizReq struct {
ID uint `v:"required"`
Name string `v:"required"`
@ -33,7 +33,7 @@ func Example_Rule_Required() {
// The Name field is required
}
func Example_Rule_RequiredIf() {
func ExampleRule_RequiredIf() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -57,7 +57,7 @@ func Example_Rule_RequiredIf() {
// The WifeName field is required
}
func Example_Rule_RequiredUnless() {
func ExampleRule_RequiredUnless() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -81,7 +81,7 @@ func Example_Rule_RequiredUnless() {
// The WifeName field is required; The HusbandName field is required
}
func Example_Rule_RequiredWith() {
func ExampleRule_RequiredWith() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -106,7 +106,7 @@ func Example_Rule_RequiredWith() {
// The HusbandName field is required
}
func Example_Rule_RequiredWithAll() {
func ExampleRule_RequiredWithAll() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -131,7 +131,7 @@ func Example_Rule_RequiredWithAll() {
// The HusbandName field is required
}
func Example_Rule_RequiredWithout() {
func ExampleRule_RequiredWithout() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -155,7 +155,7 @@ func Example_Rule_RequiredWithout() {
// The HusbandName field is required
}
func Example_Rule_RequiredWithoutAll() {
func ExampleRule_RequiredWithoutAll() {
type BizReq struct {
ID uint `v:"required" dc:"Your ID"`
Name string `v:"required" dc:"Your name"`
@ -178,7 +178,7 @@ func Example_Rule_RequiredWithoutAll() {
// The HusbandName field is required
}
func Example_Rule_Bail() {
func ExampleRule_Bail() {
type BizReq struct {
Account string `v:"bail|required|length:6,16|same:QQ"`
QQ string
@ -202,7 +202,7 @@ func Example_Rule_Bail() {
// The Account value `gf` length must be between 6 and 16
}
func Example_Rule_CaseInsensitive() {
func ExampleRule_CaseInsensitive() {
type BizReq struct {
Account string `v:"required"`
Password string `v:"required|ci|same:Password2"`
@ -223,7 +223,7 @@ func Example_Rule_CaseInsensitive() {
// output:
}
func Example_Rule_Date() {
func ExampleRule_Date() {
type BizReq struct {
Date1 string `v:"date"`
Date2 string `v:"date"`
@ -252,7 +252,7 @@ func Example_Rule_Date() {
// The Date5 value `2021/Oct/31` is not a valid date
}
func Example_Rule_Datetime() {
func ExampleRule_Datetime() {
type BizReq struct {
Date1 string `v:"datetime"`
Date2 string `v:"datetime"`
@ -279,7 +279,7 @@ func Example_Rule_Datetime() {
// The Date4 value `2021/Dec/01 23:00:00` is not a valid datetime
}
func Example_Rule_DateFormat() {
func ExampleRule_DateFormat() {
type BizReq struct {
Date1 string `v:"date-format:Y-m-d"`
Date2 string `v:"date-format:Y-m-d"`
@ -305,7 +305,7 @@ func Example_Rule_DateFormat() {
// The Date4 value `2021-11-01 23:00` does not match the format: Y-m-d H:i:s
}
func Example_Rule_Email() {
func ExampleRule_Email() {
type BizReq struct {
MailAddr1 string `v:"email"`
MailAddr2 string `v:"email"`
@ -331,7 +331,7 @@ func Example_Rule_Email() {
// The MailAddr4 value `gf#goframe.org` is not a valid email address
}
func Example_Rule_Phone() {
func ExampleRule_Phone() {
type BizReq struct {
PhoneNumber1 string `v:"phone"`
PhoneNumber2 string `v:"phone"`
@ -358,7 +358,7 @@ func Example_Rule_Phone() {
// The PhoneNumber4 value `1357891234` is not a valid phone number
}
func Example_Rule_PhoneLoose() {
func ExampleRule_PhoneLoose() {
type BizReq struct {
PhoneNumber1 string `v:"phone-loose"`
PhoneNumber2 string `v:"phone-loose"`
@ -384,7 +384,7 @@ func Example_Rule_PhoneLoose() {
// The PhoneNumber4 value `1357891234` is not a valid phone number
}
func Example_Rule_Telephone() {
func ExampleRule_Telephone() {
type BizReq struct {
Telephone1 string `v:"telephone"`
Telephone2 string `v:"telephone"`
@ -410,7 +410,7 @@ func Example_Rule_Telephone() {
// The Telephone4 value `775421451` is not a valid telephone number
}
func Example_Rule_Passport() {
func ExampleRule_Passport() {
type BizReq struct {
Passport1 string `v:"passport"`
Passport2 string `v:"passport"`
@ -437,7 +437,7 @@ func Example_Rule_Passport() {
// The Passport4 value `gf` is not a valid passport format
}
func Example_Rule_Password() {
func ExampleRule_Password() {
type BizReq struct {
Password1 string `v:"password"`
Password2 string `v:"password"`
@ -458,7 +458,7 @@ func Example_Rule_Password() {
// The Password2 value `gofra` is not a valid password format
}
func Example_Rule_Password2() {
func ExampleRule_Password2() {
type BizReq struct {
Password1 string `v:"password2"`
Password2 string `v:"password2"`
@ -485,7 +485,7 @@ func Example_Rule_Password2() {
// The Password4 value `goframe123` is not a valid password format
}
func Example_Rule_Password3() {
func ExampleRule_Password3() {
type BizReq struct {
Password1 string `v:"password3"`
Password2 string `v:"password3"`
@ -509,7 +509,7 @@ func Example_Rule_Password3() {
// The Password3 value `Goframe123` is not a valid password format
}
func Example_Rule_Postcode() {
func ExampleRule_Postcode() {
type BizReq struct {
Postcode1 string `v:"postcode"`
Postcode2 string `v:"postcode"`
@ -533,7 +533,7 @@ func Example_Rule_Postcode() {
// The Postcode3 value `1000000` is not a valid postcode format
}
func Example_Rule_ResidentId() {
func ExampleRule_ResidentId() {
type BizReq struct {
ResidentID1 string `v:"resident-id"`
}
@ -552,7 +552,7 @@ func Example_Rule_ResidentId() {
// The ResidentID1 value `320107199506285482` is not a valid resident id number
}
func Example_Rule_BankCard() {
func ExampleRule_BankCard() {
type BizReq struct {
BankCard1 string `v:"bank-card"`
}
@ -571,7 +571,7 @@ func Example_Rule_BankCard() {
// The BankCard1 value `6225760079930218` is not a valid bank card number
}
func Example_Rule_QQ() {
func ExampleRule_QQ() {
type BizReq struct {
QQ1 string `v:"qq"`
QQ2 string `v:"qq"`
@ -595,7 +595,7 @@ func Example_Rule_QQ() {
// The QQ3 value `514258412a` is not a valid QQ number
}
func Example_Rule_IP() {
func ExampleRule_IP() {
type BizReq struct {
IP1 string `v:"ip"`
IP2 string `v:"ip"`
@ -621,7 +621,7 @@ func Example_Rule_IP() {
// The IP4 value `ze80::812b:1158:1f43:f0d1` is not a valid IP address
}
func Example_Rule_IPV4() {
func ExampleRule_IPV4() {
type BizReq struct {
IP1 string `v:"ipv4"`
IP2 string `v:"ipv4"`
@ -642,7 +642,7 @@ func Example_Rule_IPV4() {
// The IP2 value `520.255.255.255` is not a valid IPv4 address
}
func Example_Rule_IPV6() {
func ExampleRule_IPV6() {
type BizReq struct {
IP1 string `v:"ipv6"`
IP2 string `v:"ipv6"`
@ -663,7 +663,7 @@ func Example_Rule_IPV6() {
// The IP2 value `ze80::812b:1158:1f43:f0d1` is not a valid IPv6 address
}
func Example_Rule_Mac() {
func ExampleRule_Mac() {
type BizReq struct {
Mac1 string `v:"mac"`
Mac2 string `v:"mac"`
@ -684,7 +684,7 @@ func Example_Rule_Mac() {
// The Mac2 value `Z0-CC-6A-D6-B1-1A` is not a valid MAC address
}
func Example_Rule_Url() {
func ExampleRule_Url() {
type BizReq struct {
URL1 string `v:"url"`
URL2 string `v:"url"`
@ -707,7 +707,7 @@ func Example_Rule_Url() {
// The URL3 value `ws://goframe.org` is not a valid URL address
}
func Example_Rule_Domain() {
func ExampleRule_Domain() {
type BizReq struct {
Domain1 string `v:"domain"`
Domain2 string `v:"domain"`
@ -733,7 +733,7 @@ func Example_Rule_Domain() {
// The Domain4 value `1a.2b` is not a valid domain format
}
func Example_Rule_Size() {
func ExampleRule_Size() {
type BizReq struct {
Size1 string `v:"size:10"`
Size2 string `v:"size:5"`
@ -754,7 +754,7 @@ func Example_Rule_Size() {
// The Size2 value `goframe` length must be 5
}
func Example_Rule_Length() {
func ExampleRule_Length() {
type BizReq struct {
Length1 string `v:"length:5,10"`
Length2 string `v:"length:10,15"`
@ -775,7 +775,7 @@ func Example_Rule_Length() {
// The Length2 value `goframe` length must be between 10 and 15
}
func Example_Rule_MinLength() {
func ExampleRule_MinLength() {
type BizReq struct {
MinLength1 string `v:"min-length:10"`
MinLength2 string `v:"min-length:8"`
@ -796,7 +796,7 @@ func Example_Rule_MinLength() {
// The MinLength2 value `goframe` length must be equal or greater than 8
}
func Example_Rule_MaxLength() {
func ExampleRule_MaxLength() {
type BizReq struct {
MaxLength1 string `v:"max-length:10"`
MaxLength2 string `v:"max-length:5"`
@ -817,7 +817,7 @@ func Example_Rule_MaxLength() {
// The MaxLength2 value `goframe` length must be equal or lesser than 5
}
func Example_Rule_Between() {
func ExampleRule_Between() {
type BizReq struct {
Age1 int `v:"between:1,100"`
Age2 int `v:"between:1,100"`
@ -843,7 +843,7 @@ func Example_Rule_Between() {
// The Score2 value `-0.5` must be between 0 and 10
}
func Example_Rule_Min() {
func ExampleRule_Min() {
type BizReq struct {
Age1 int `v:"min:100"`
Age2 int `v:"min:100"`
@ -869,7 +869,7 @@ func Example_Rule_Min() {
// The Score1 value `9.8` must be equal or greater than 10
}
func Example_Rule_Max() {
func ExampleRule_Max() {
type BizReq struct {
Age1 int `v:"max:100"`
Age2 int `v:"max:100"`
@ -895,7 +895,7 @@ func Example_Rule_Max() {
// The Score2 value `10.1` must be equal or lesser than 10
}
func Example_Rule_Json() {
func ExampleRule_Json() {
type BizReq struct {
JSON1 string `v:"json"`
JSON2 string `v:"json"`
@ -916,7 +916,7 @@ func Example_Rule_Json() {
// The JSON2 value `{"name":"goframe","author":"郭强","test"}` is not a valid JSON string
}
func Example_Rule_Integer() {
func ExampleRule_Integer() {
type BizReq struct {
Integer string `v:"integer"`
Float string `v:"integer"`
@ -940,7 +940,7 @@ func Example_Rule_Integer() {
// The Str value `goframe` is not an integer
}
func Example_Rule_Float() {
func ExampleRule_Float() {
type BizReq struct {
Integer string `v:"float"`
Float string `v:"float"`
@ -963,7 +963,7 @@ func Example_Rule_Float() {
// The Str value `goframe` is not of valid float type
}
func Example_Rule_Boolean() {
func ExampleRule_Boolean() {
type BizReq struct {
Boolean bool `v:"boolean"`
Integer int `v:"boolean"`
@ -993,7 +993,7 @@ func Example_Rule_Boolean() {
// The Str3 value `goframe` field must be true or false
}
func Example_Rule_Same() {
func ExampleRule_Same() {
type BizReq struct {
Name string `v:"required"`
Password string `v:"required|same:Password2"`
@ -1015,7 +1015,7 @@ func Example_Rule_Same() {
// The Password value `goframe.org` must be the same as field Password2
}
func Example_Rule_Different() {
func ExampleRule_Different() {
type BizReq struct {
Name string `v:"required"`
MailAddr string `v:"required"`
@ -1037,7 +1037,7 @@ func Example_Rule_Different() {
// The OtherMailAddr value `gf@goframe.org` must be different from field MailAddr
}
func Example_Rule_In() {
func ExampleRule_In() {
type BizReq struct {
ID uint `v:"required" dc:"Your Id"`
Name string `v:"required" dc:"Your name"`
@ -1059,7 +1059,7 @@ func Example_Rule_In() {
// The Gender value `3` is not in acceptable range: 0,1,2
}
func Example_Rule_NotIn() {
func ExampleRule_NotIn() {
type BizReq struct {
ID uint `v:"required" dc:"Your Id"`
Name string `v:"required" dc:"Your name"`
@ -1081,7 +1081,7 @@ func Example_Rule_NotIn() {
// The InvalidIndex value `1` must not be in range: -1,0,1
}
func Example_Rule_Regex() {
func ExampleRule_Regex() {
type BizReq struct {
Regex1 string `v:"regex:[1-9][0-9]{4,14}"`
Regex2 string `v:"regex:[1-9][0-9]{4,14}"`
@ -1104,7 +1104,7 @@ func Example_Rule_Regex() {
// The Regex2 value `01234` must be in regex of: [1-9][0-9]{4,14}
}
func Example_Rule_NotRegex() {
func ExampleRule_NotRegex() {
type BizReq struct {
Regex1 string `v:"regex:\\d{4}"`
Regex2 string `v:"not-regex:\\d{4}"`
@ -1124,7 +1124,7 @@ func Example_Rule_NotRegex() {
// The Regex2 value `1234` should not be in regex of: \d{4}
}
func Example_Rule_After() {
func ExampleRule_After() {
type BizReq struct {
Time1 string
Time2 string `v:"after:Time1"`
@ -1146,7 +1146,7 @@ func Example_Rule_After() {
// The Time2 value `2022-09-01` must be after field Time1 value `2022-09-01`
}
func Example_Rule_AfterEqual() {
func ExampleRule_AfterEqual() {
type BizReq struct {
Time1 string
Time2 string `v:"after-equal:Time1"`
@ -1168,7 +1168,7 @@ func Example_Rule_AfterEqual() {
// The Time2 value `2022-09-01` must be after or equal to field Time1 value `2022-09-02`
}
func Example_Rule_Before() {
func ExampleRule_Before() {
type BizReq struct {
Time1 string `v:"before:Time3"`
Time2 string `v:"before:Time3"`
@ -1190,7 +1190,7 @@ func Example_Rule_Before() {
// The Time2 value `2022-09-03` must be before field Time3 value `2022-09-03`
}
func Example_Rule_BeforeEqual() {
func ExampleRule_BeforeEqual() {
type BizReq struct {
Time1 string `v:"before-equal:Time3"`
Time2 string `v:"before-equal:Time3"`
@ -1212,7 +1212,7 @@ func Example_Rule_BeforeEqual() {
// The Time1 value `2022-09-02` must be before or equal to field Time3
}
func Example_Rule_Array() {
func ExampleRule_Array() {
type BizReq struct {
Value1 string `v:"array"`
Value2 string `v:"array"`
@ -1236,7 +1236,7 @@ func Example_Rule_Array() {
// The Value1 value `1,2,3` is not of valid array type
}
func Example_Rule_EQ() {
func ExampleRule_EQ() {
type BizReq struct {
Name string `v:"required"`
Password string `v:"required|eq:Password2"`
@ -1258,7 +1258,7 @@ func Example_Rule_EQ() {
// The Password value `goframe.org` must be equal to field Password2 value `goframe.net`
}
func Example_Rule_NotEQ() {
func ExampleRule_NotEQ() {
type BizReq struct {
Name string `v:"required"`
MailAddr string `v:"required"`
@ -1280,7 +1280,7 @@ func Example_Rule_NotEQ() {
// The OtherMailAddr value `gf@goframe.org` must not be equal to field MailAddr value `gf@goframe.org`
}
func Example_Rule_GT() {
func ExampleRule_GT() {
type BizReq struct {
Value1 int
Value2 int `v:"gt:Value1"`
@ -1302,7 +1302,7 @@ func Example_Rule_GT() {
// The Value2 value `1` must be greater than field Value1 value `1`
}
func Example_Rule_GTE() {
func ExampleRule_GTE() {
type BizReq struct {
Value1 int
Value2 int `v:"gte:Value1"`
@ -1324,7 +1324,7 @@ func Example_Rule_GTE() {
// The Value2 value `1` must be greater than or equal to field Value1 value `2`
}
func Example_Rule_LT() {
func ExampleRule_LT() {
type BizReq struct {
Value1 int
Value2 int `v:"lt:Value1"`
@ -1346,7 +1346,7 @@ func Example_Rule_LT() {
// The Value3 value `2` must be lesser than field Value1 value `2`
}
func Example_Rule_LTE() {
func ExampleRule_LTE() {
type BizReq struct {
Value1 int
Value2 int `v:"lte:Value1"`
@ -1368,7 +1368,7 @@ func Example_Rule_LTE() {
// The Value3 value `2` must be lesser than or equal to field Value1 value `1`
}
func Example_Rule_Foreach() {
func ExampleRule_Foreach() {
type BizReq struct {
Value1 []int `v:"foreach|in:1,2,3"`
Value2 []int `v:"foreach|in:1,2,3"`