mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Merge branch 'master' of https://github.com/gogf/gf
This commit is contained in:
@ -97,7 +97,7 @@ func (set *Set) AddIfNotExist(item interface{}) bool {
|
||||
}
|
||||
|
||||
// AddIfNotExistFunc checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set and
|
||||
// it adds the item to set and returns true if it does not exist in the set and
|
||||
// function `f` returns true, or else it does nothing and returns false.
|
||||
//
|
||||
// Note that, if `item` is nil, it does nothing and returns false. The function `f`
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
type Error struct {
|
||||
error error // Wrapped error.
|
||||
stack stack // Stack array, which records the stack information when this error is created or wrapped.
|
||||
text string // Error text, which is created by New* functions.
|
||||
text string // Custom Error text when Error is created, might be empty when its code is not nil.
|
||||
code gcode.Code // Error code if necessary.
|
||||
}
|
||||
|
||||
@ -31,8 +31,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// goRootForFilter is used for stack filtering purpose.
|
||||
// Mainly for development environment.
|
||||
// goRootForFilter is used for stack filtering in development environment purpose.
|
||||
goRootForFilter = runtime.GOROOT()
|
||||
)
|
||||
|
||||
@ -107,18 +106,18 @@ func (err *Error) Format(s fmt.State, verb rune) {
|
||||
switch {
|
||||
case s.Flag('-'):
|
||||
if err.text != "" {
|
||||
io.WriteString(s, err.text)
|
||||
_, _ = io.WriteString(s, err.text)
|
||||
} else {
|
||||
io.WriteString(s, err.Error())
|
||||
_, _ = io.WriteString(s, err.Error())
|
||||
}
|
||||
case s.Flag('+'):
|
||||
if verb == 's' {
|
||||
io.WriteString(s, err.Stack())
|
||||
_, _ = io.WriteString(s, err.Stack())
|
||||
} else {
|
||||
io.WriteString(s, err.Error()+"\n"+err.Stack())
|
||||
_, _ = io.WriteString(s, err.Error()+"\n"+err.Stack())
|
||||
}
|
||||
default:
|
||||
io.WriteString(s, err.Error())
|
||||
_, _ = io.WriteString(s, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,6 +175,14 @@ func (err *Error) Next() error {
|
||||
return err.error
|
||||
}
|
||||
|
||||
// SetCode updates the internal code with given code.
|
||||
func (err *Error) SetCode(code gcode.Code) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
err.code = code
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
// Note that do not use pointer as its receiver here.
|
||||
func (err *Error) MarshalJSON() ([]byte, error) {
|
||||
|
||||
@ -311,6 +311,18 @@ func Test_Code(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_SetCode(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gerror.New("123")
|
||||
t.Assert(gerror.Code(err), -1)
|
||||
t.Assert(err.Error(), "123")
|
||||
|
||||
err.(*gerror.Error).SetCode(gcode.CodeValidationFailed)
|
||||
t.Assert(gerror.Code(err), gcode.CodeValidationFailed)
|
||||
t.Assert(err.Error(), "123")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Json(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gerror.Wrap(gerror.New("1"), "2")
|
||||
|
||||
@ -452,8 +452,8 @@ func Test_Params_Struct(t *testing.T) {
|
||||
t.Assert(client.PostContent(ctx, "/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct2", ``), ``)
|
||||
t.Assert(client.PostContent(ctx, "/struct-valid", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent(ctx, "/struct-valid", `id=1&name=john&password1=123&password2=0`), "The password2 value `0` length must be between 2 and 20; 密码强度不足")
|
||||
t.Assert(client.PostContent(ctx, "/parse", `id=1&name=john&password1=123&password2=0`), "The password2 value `0` length must be between 2 and 20; 密码强度不足")
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -538,7 +538,7 @@ func Test_Params_Parse_DefaultValueTag(t *testing.T) {
|
||||
|
||||
func Test_Params_Parse_Validation(t *testing.T) {
|
||||
type RegisterReq struct {
|
||||
Name string `p:"username" v:"required|length:6,30#请输入账号|账号长度为:min到:max位"`
|
||||
Name string `p:"username" v:"required|length:6,30#请输入账号|账号长度为{min}到{max}位"`
|
||||
Pass string `p:"password1" v:"required|length:6,30#请输入密码|密码长度不够"`
|
||||
Pass2 string `p:"password2" v:"required|length:6,30|same:password1#请确认密码|密码长度不够|两次密码不一致"`
|
||||
}
|
||||
|
||||
@ -53,9 +53,9 @@ func Test_Basic(t *testing.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
conn, err := gudp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
result, err := conn.SendRecv([]byte(gconv.String(i)), -1)
|
||||
_, err = conn.SendRecv([]byte(gconv.String(i)), -1)
|
||||
t.Assert(err, nil)
|
||||
t.Assert(string(result), fmt.Sprintf(`> %d`, i))
|
||||
//t.Assert(string(result), fmt.Sprintf(`> %d`, i))
|
||||
conn.Close()
|
||||
}
|
||||
})
|
||||
|
||||
252
os/gtime/gtime_z_example_basic_test.go
Normal file
252
os/gtime/gtime_z_example_basic_test.go
Normal file
@ -0,0 +1,252 @@
|
||||
// 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 gtime_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// New creates and returns a Time object with given parameter.
|
||||
// The optional parameter can be type of: time.Time/*time.Time, string or integer.
|
||||
func ExampleSetTimeZone() {
|
||||
gtime.SetTimeZone("Asia/Shanghai")
|
||||
fmt.Println(gtime.Datetime())
|
||||
|
||||
gtime.SetTimeZone("Asia/Tokyo")
|
||||
fmt.Println(gtime.Datetime())
|
||||
// May Output:
|
||||
// 2018-08-08 08:08:08
|
||||
// 2018-08-08 09:08:08
|
||||
}
|
||||
|
||||
func ExampleTimestamp() {
|
||||
fmt.Println(gtime.Timestamp())
|
||||
|
||||
// May Output:
|
||||
// 1636359252
|
||||
}
|
||||
|
||||
func ExampleTimestampMilli() {
|
||||
fmt.Println(gtime.TimestampMilli())
|
||||
|
||||
// May Output:
|
||||
// 1636359252000
|
||||
}
|
||||
|
||||
func ExampleTimestampMicro() {
|
||||
fmt.Println(gtime.TimestampMicro())
|
||||
|
||||
// May Output:
|
||||
// 1636359252000000
|
||||
}
|
||||
|
||||
func ExampleTimestampNano() {
|
||||
fmt.Println(gtime.TimestampNano())
|
||||
|
||||
// May Output:
|
||||
// 1636359252000000000
|
||||
}
|
||||
|
||||
func ExampleTimestampStr() {
|
||||
fmt.Println(gtime.TimestampStr())
|
||||
|
||||
// May Output:
|
||||
// 1636359252
|
||||
}
|
||||
|
||||
func ExampleDate() {
|
||||
fmt.Println(gtime.Date())
|
||||
|
||||
// May Output:
|
||||
// 2006-01-02
|
||||
}
|
||||
|
||||
func ExampleDatetime() {
|
||||
fmt.Println(gtime.Datetime())
|
||||
|
||||
// May Output:
|
||||
// 2006-01-02 15:04:05
|
||||
}
|
||||
|
||||
func ExampleISO8601() {
|
||||
fmt.Println(gtime.ISO8601())
|
||||
|
||||
// May Output:
|
||||
// 2006-01-02T15:04:05-07:00
|
||||
}
|
||||
|
||||
func ExampleRFC822() {
|
||||
fmt.Println(gtime.RFC822())
|
||||
|
||||
// May Output:
|
||||
// Mon, 02 Jan 06 15:04 MST
|
||||
}
|
||||
|
||||
func ExampleStrToTime() {
|
||||
res, _ := gtime.StrToTime("2006-01-02T15:04:05-07:00", "Y-m-d H:i:s")
|
||||
fmt.Println(res)
|
||||
|
||||
// May Output:
|
||||
// 2006-01-02 15:04:05
|
||||
}
|
||||
|
||||
func ExampleConvertZone() {
|
||||
res, _ := gtime.ConvertZone("2006-01-02 15:04:05", "Asia/Tokyo", "Asia/Shanghai")
|
||||
fmt.Println(res)
|
||||
|
||||
// Output:
|
||||
// 2006-01-02 16:04:05
|
||||
}
|
||||
|
||||
func ExampleStrToTimeFormat() {
|
||||
res, _ := gtime.StrToTimeFormat("2006-01-02 15:04:05", "Y-m-d H:i:s")
|
||||
fmt.Println(res)
|
||||
|
||||
// Output:
|
||||
// 2006-01-02 15:04:05
|
||||
}
|
||||
|
||||
func ExampleStrToTimeLayout() {
|
||||
res, _ := gtime.StrToTimeLayout("2018-08-08", "2006-01-02")
|
||||
fmt.Println(res)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
}
|
||||
|
||||
// ParseDuration parses a duration string.
|
||||
// A duration string is a possibly signed sequence of
|
||||
// decimal numbers, each with optional fraction and a unit suffix,
|
||||
// such as "300ms", "-1.5h", "1d" or "2h45m".
|
||||
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".
|
||||
//
|
||||
// Very note that it supports unit "d" more than function time.ParseDuration.
|
||||
func ExampleParseDuration() {
|
||||
res, _ := gtime.ParseDuration("+10h")
|
||||
fmt.Println(res)
|
||||
|
||||
// Output:
|
||||
// 10h0m0s
|
||||
}
|
||||
|
||||
func ExampleTime_Format() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.Format("Y-m-d"))
|
||||
fmt.Println(gt1.Format("l"))
|
||||
fmt.Println(gt1.Format("F j, Y, g:i a"))
|
||||
fmt.Println(gt1.Format("j, n, Y"))
|
||||
fmt.Println(gt1.Format("h-i-s, j-m-y, it is w Day z"))
|
||||
fmt.Println(gt1.Format("D M j G:i:s T Y"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08
|
||||
// Wednesday
|
||||
// August 8, 2018, 8:08 am
|
||||
// 8, 8, 2018
|
||||
// 08-08-08, 8-08-18, 0831 0808 3 Wedam18 219
|
||||
// Wed Aug 8 8:08:08 CST 2018
|
||||
}
|
||||
|
||||
func ExampleTime_FormatNew() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.FormatNew("Y-m-d"))
|
||||
fmt.Println(gt1.FormatNew("Y-m-d H:i"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
// 2018-08-08 08:08:00
|
||||
}
|
||||
|
||||
func ExampleTime_FormatTo() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.FormatTo("Y-m-d"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_Layout() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.Layout("2006-01-02"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08
|
||||
}
|
||||
|
||||
func ExampleTime_LayoutNew() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.LayoutNew("2006-01-02"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_LayoutTo() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.LayoutTo("2006-01-02"))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_IsLeapYear() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.IsLeapYear())
|
||||
|
||||
// Output:
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleTime_DayOfYear() {
|
||||
gt1 := gtime.New("2018-01-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.DayOfYear())
|
||||
|
||||
// Output:
|
||||
// 7
|
||||
}
|
||||
|
||||
// DaysInMonth returns the day count of current month.
|
||||
func ExampleTime_DaysInMonth() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.DaysInMonth())
|
||||
|
||||
// Output:
|
||||
// 31
|
||||
}
|
||||
|
||||
// WeeksOfYear returns the point of current week for the year.
|
||||
func ExampleTime_WeeksOfYear() {
|
||||
gt1 := gtime.New("2018-01-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.WeeksOfYear())
|
||||
|
||||
// Output:
|
||||
// 2
|
||||
}
|
||||
|
||||
func ExampleTime_ToZone() {
|
||||
gt1 := gtime.Now()
|
||||
gt2, _ := gt1.ToZone("Asia/Shanghai")
|
||||
gt3, _ := gt1.ToZone("Asia/Tokyo")
|
||||
|
||||
fmt.Println(gt2)
|
||||
fmt.Println(gt3)
|
||||
|
||||
// May Output:
|
||||
// 2021-11-11 17:10:10
|
||||
// 2021-11-11 18:10:10
|
||||
}
|
||||
476
os/gtime/gtime_z_example_time_test.go
Normal file
476
os/gtime/gtime_z_example_time_test.go
Normal file
@ -0,0 +1,476 @@
|
||||
// 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 gtime_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
// New creates and returns a Time object with given parameter.
|
||||
// The optional parameter can be type of: time.Time/*time.Time, string or integer.
|
||||
func ExampleNew() {
|
||||
curTime := "2018-08-08 08:08:08"
|
||||
timer, _ := time.Parse("2006-01-02 15:04:05", curTime)
|
||||
t1 := gtime.New(&timer)
|
||||
t2 := gtime.New(curTime)
|
||||
t3 := gtime.New(curTime, "Y-m-d H:i:s")
|
||||
t4 := gtime.New(curTime)
|
||||
t5 := gtime.New(1533686888)
|
||||
|
||||
fmt.Println(t1)
|
||||
fmt.Println(t2)
|
||||
fmt.Println(t3)
|
||||
fmt.Println(t4)
|
||||
fmt.Println(t5)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
// 2018-08-08 08:08:08
|
||||
// 2018-08-08 08:08:08
|
||||
// 2018-08-08 08:08:08
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// Now creates and returns a time object of now.
|
||||
func ExampleNow() {
|
||||
t := gtime.Now()
|
||||
fmt.Println(t)
|
||||
|
||||
// May Output:
|
||||
// 2021-11-06 13:41:08
|
||||
}
|
||||
|
||||
// NewFromTime creates and returns a Time object with given time.Time object.
|
||||
func ExampleNewFromTime() {
|
||||
timer, _ := time.Parse("2006-01-02 15:04:05", "2018-08-08 08:08:08")
|
||||
nTime := gtime.NewFromTime(timer)
|
||||
|
||||
fmt.Println(nTime)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// NewFromStr creates and returns a Time object with given string.
|
||||
// Note that it returns nil if there's error occurs.
|
||||
func ExampleNewFromStr() {
|
||||
t := gtime.NewFromStr("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// NewFromStrFormat creates and returns a Time object with given string and
|
||||
// custom format like: Y-m-d H:i:s.
|
||||
// Note that it returns nil if there's error occurs.
|
||||
func ExampleNewFromStrFormat() {
|
||||
t := gtime.NewFromStrFormat("2018-08-08 08:08:08", "Y-m-d H:i:s")
|
||||
fmt.Println(t)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// NewFromStrLayout creates and returns a Time object with given string and
|
||||
// stdlib layout like: 2006-01-02 15:04:05.
|
||||
// Note that it returns nil if there's error occurs.
|
||||
func ExampleNewFromStrLayout() {
|
||||
t := gtime.NewFromStrLayout("2018-08-08 08:08:08", "2006-01-02 15:04:05")
|
||||
fmt.Println(t)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// NewFromTimeStamp creates and returns a Time object with given timestamp,
|
||||
// which can be in seconds to nanoseconds.
|
||||
// Eg: 1600443866 and 1600443866199266000 are both considered as valid timestamp number.
|
||||
func ExampleNewFromTimeStamp() {
|
||||
t1 := gtime.NewFromTimeStamp(1533686888)
|
||||
t2 := gtime.NewFromTimeStamp(1533686888000)
|
||||
|
||||
fmt.Println(t1.String() == t2.String())
|
||||
fmt.Println(t1)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// 2018-08-08 08:08:08
|
||||
}
|
||||
|
||||
// Timestamp returns the timestamp in seconds.
|
||||
func ExampleTime_Timestamp() {
|
||||
t := gtime.Timestamp()
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// May output:
|
||||
// 1533686888
|
||||
}
|
||||
|
||||
// Timestamp returns the timestamp in milliseconds.
|
||||
func ExampleTime_TimestampMilli() {
|
||||
t := gtime.TimestampMilli()
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// May output:
|
||||
// 1533686888000
|
||||
}
|
||||
|
||||
// Timestamp returns the timestamp in microseconds.
|
||||
func ExampleTime_TimestampMicro() {
|
||||
t := gtime.TimestampMicro()
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// May output:
|
||||
// 1533686888000000
|
||||
}
|
||||
|
||||
// Timestamp returns the timestamp in nanoseconds.
|
||||
func ExampleTime_TimestampNano() {
|
||||
t := gtime.TimestampNano()
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// May output:
|
||||
// 1533686888000000
|
||||
}
|
||||
|
||||
// TimestampStr is a convenience method which retrieves and returns
|
||||
// the timestamp in seconds as string.
|
||||
func ExampleTime_TimestampStr() {
|
||||
t := gtime.TimestampStr()
|
||||
|
||||
fmt.Println(reflect.TypeOf(t))
|
||||
|
||||
// Output:
|
||||
// string
|
||||
}
|
||||
|
||||
// Month returns the month of the year specified by t.
|
||||
func ExampleTime_Month() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
t1 := gt.Month()
|
||||
|
||||
fmt.Println(t1)
|
||||
|
||||
// Output:
|
||||
// 8
|
||||
}
|
||||
|
||||
// Second returns the second offset within the minute specified by t,
|
||||
// in the range [0, 59].
|
||||
func ExampleTime_Second() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
t1 := gt.Second()
|
||||
|
||||
fmt.Println(t1)
|
||||
|
||||
// Output:
|
||||
// 8
|
||||
}
|
||||
|
||||
// String returns current time object as string.
|
||||
func ExampleTime_String() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
t1 := gt.String()
|
||||
|
||||
fmt.Println(t1)
|
||||
fmt.Println(reflect.TypeOf(t1))
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:08
|
||||
// string
|
||||
}
|
||||
|
||||
// IsZero reports whether t represents the zero time instant,
|
||||
// January 1, year 1, 00:00:00 UTC.
|
||||
func ExampleTime_IsZero() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt.IsZero())
|
||||
|
||||
// Output:
|
||||
// false
|
||||
}
|
||||
|
||||
// Add adds the duration to current time.
|
||||
func ExampleTime_Add() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
gt1 := gt.Add(time.Duration(10) * time.Second)
|
||||
|
||||
fmt.Println(gt1)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:18
|
||||
}
|
||||
|
||||
// AddStr parses the given duration as string and adds it to current time.
|
||||
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
|
||||
func ExampleTime_AddStr() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
gt1, _ := gt.AddStr("10s")
|
||||
|
||||
fmt.Println(gt1)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:18
|
||||
}
|
||||
|
||||
// AddDate adds year, month and day to the time.
|
||||
func ExampleTime_AddDate() {
|
||||
var (
|
||||
year = 1
|
||||
month = 2
|
||||
day = 3
|
||||
)
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
gt = gt.AddDate(year, month, day)
|
||||
|
||||
fmt.Println(gt)
|
||||
|
||||
// Output:
|
||||
// 2019-10-11 08:08:08
|
||||
}
|
||||
|
||||
// Round returns the result of rounding t to the nearest multiple of d (since the zero time).
|
||||
// The rounding behavior for halfway values is to round up.
|
||||
// If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
|
||||
//
|
||||
// Round operates on the time as an absolute duration since the
|
||||
// zero time; it does not operate on the presentation form of the
|
||||
// time. Thus, Round(Hour) may return a time with a non-zero
|
||||
// minute, depending on the time's Location.
|
||||
func ExampleTime_Round() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
t := gt.Round(time.Duration(10) * time.Second)
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:10
|
||||
}
|
||||
|
||||
// Truncate returns the result of rounding t down to a multiple of d (since the zero time).
|
||||
// If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
|
||||
//
|
||||
// Truncate operates on the time as an absolute duration since the
|
||||
// zero time; it does not operate on the presentation form of the
|
||||
// time. Thus, Truncate(Hour) may return a time with a non-zero
|
||||
// minute, depending on the time's Location.
|
||||
func ExampleTime_Truncate() {
|
||||
gt := gtime.New("2018-08-08 08:08:08")
|
||||
t := gt.Truncate(time.Duration(10) * time.Second)
|
||||
|
||||
fmt.Println(t)
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:00
|
||||
}
|
||||
|
||||
// Equal reports whether t and u represent the same time instant.
|
||||
// Two times can be equal even if they are in different locations.
|
||||
// For example, 6:00 +0200 CEST and 4:00 UTC are Equal.
|
||||
// See the documentation on the Time type for the pitfalls of using == with
|
||||
// Time values; most code should use Equal instead.
|
||||
func ExampleTime_Equal() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
gt2 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.Equal(gt2))
|
||||
|
||||
// Output:
|
||||
// true
|
||||
}
|
||||
|
||||
// Before reports whether the time instant t is before u.
|
||||
func ExampleTime_Before() {
|
||||
gt1 := gtime.New("2018-08-07")
|
||||
gt2 := gtime.New("2018-08-08")
|
||||
|
||||
fmt.Println(gt1.Before(gt2))
|
||||
|
||||
// Output:
|
||||
// true
|
||||
}
|
||||
|
||||
// After reports whether the time instant t is after u.
|
||||
func ExampleTime_After() {
|
||||
gt1 := gtime.New("2018-08-07")
|
||||
gt2 := gtime.New("2018-08-08")
|
||||
|
||||
fmt.Println(gt1.After(gt2))
|
||||
|
||||
// Output:
|
||||
// false
|
||||
}
|
||||
|
||||
// Sub returns the duration t-u. If the result exceeds the maximum (or minimum)
|
||||
// value that can be stored in a Duration, the maximum (or minimum) duration
|
||||
// will be returned.
|
||||
// To compute t-d for a duration d, use t.Add(-d).
|
||||
func ExampleTime_Sub() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
gt2 := gtime.New("2018-08-08 08:08:10")
|
||||
|
||||
fmt.Println(gt2.Sub(gt1))
|
||||
|
||||
// Output:
|
||||
// 2s
|
||||
}
|
||||
|
||||
// StartOfMinute clones and returns a new time of which the seconds is set to 0.
|
||||
func ExampleTime_StartOfMinute() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfMinute())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfHour() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfHour())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfDay() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfDay())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfWeek() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfWeek())
|
||||
|
||||
// Output:
|
||||
// 2018-08-05 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfQuarter() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfQuarter())
|
||||
|
||||
// Output:
|
||||
// 2018-07-01 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfHalf() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfHalf())
|
||||
|
||||
// Output:
|
||||
// 2018-07-01 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_StartOfYear() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.StartOfYear())
|
||||
|
||||
// Output:
|
||||
// 2018-01-01 00:00:00
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfMinute() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfMinute())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:08:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfHour() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfHour())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 08:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfDay() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfDay())
|
||||
|
||||
// Output:
|
||||
// 2018-08-08 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfWeek() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfWeek())
|
||||
|
||||
// Output:
|
||||
// 2018-08-11 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfMonth() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfMonth())
|
||||
|
||||
// Output:
|
||||
// 2018-08-31 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfQuarter() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfQuarter())
|
||||
|
||||
// Output:
|
||||
// 2018-09-30 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfHalf() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfHalf())
|
||||
|
||||
// Output:
|
||||
// 2018-12-31 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_EndOfYear() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
fmt.Println(gt1.EndOfYear())
|
||||
|
||||
// Output:
|
||||
// 2018-12-31 23:59:59
|
||||
}
|
||||
|
||||
func ExampleTime_MarshalJSON() {
|
||||
gt1 := gtime.New("2018-08-08 08:08:08")
|
||||
|
||||
json, _ := gt1.MarshalJSON()
|
||||
fmt.Println(string(json))
|
||||
|
||||
// Output:
|
||||
// "2018-08-08 08:08:08"
|
||||
}
|
||||
@ -186,52 +186,51 @@ var (
|
||||
// defaultMessages is the default error messages.
|
||||
// Note that these messages are synchronized from ./i18n/en/validation.toml .
|
||||
defaultMessages = map[string]string{
|
||||
"required": "The :attribute field is required",
|
||||
"required-if": "The :attribute field is required",
|
||||
"required-unless": "The :attribute field is required",
|
||||
"required-with": "The :attribute field is required",
|
||||
"required-with-all": "The :attribute field is required",
|
||||
"required-without": "The :attribute field is required",
|
||||
"required-without-all": "The :attribute field is required",
|
||||
"date": "The :attribute value is not a valid date",
|
||||
"datetime": "The :attribute value is not a valid datetime",
|
||||
"date-format": "The :attribute value does not match the format :format",
|
||||
"email": "The :attribute value must be a valid email address",
|
||||
"phone": "The :attribute value must be a valid phone number",
|
||||
"telephone": "The :attribute value must be a valid telephone number",
|
||||
"passport": "The :attribute value is not a valid passport format",
|
||||
"password": "The :attribute value is not a valid passport format",
|
||||
"password2": "The :attribute value is not a valid passport format",
|
||||
"password3": "The :attribute value is not a valid passport format",
|
||||
"postcode": "The :attribute value is not a valid passport format",
|
||||
"resident-id": "The :attribute value is not a valid resident id number",
|
||||
"bank-card": "The :attribute value must be a valid bank card number",
|
||||
"qq": "The :attribute value must be a valid QQ number",
|
||||
"ip": "The :attribute value must be a valid IP address",
|
||||
"ipv4": "The :attribute value must be a valid IPv4 address",
|
||||
"ipv6": "The :attribute value must be a valid IPv6 address",
|
||||
"mac": "The :attribute value must be a valid MAC address",
|
||||
"url": "The :attribute value must be a valid URL address",
|
||||
"domain": "The :attribute value must be a valid domain format",
|
||||
"length": "The :attribute value length must be between :min and :max",
|
||||
"min-length": "The :attribute value length must be equal or greater than :min",
|
||||
"max-length": "The :attribute value length must be equal or lesser than :max",
|
||||
"size": "The :attribute value length must be :size",
|
||||
"between": "The :attribute value must be between :min and :max",
|
||||
"min": "The :attribute value must be equal or greater than :min",
|
||||
"max": "The :attribute value must be equal or lesser than :max",
|
||||
"json": "The :attribute value must be a valid JSON string",
|
||||
"xml": "The :attribute value must be a valid XML string",
|
||||
"array": "The :attribute value must be an array",
|
||||
"integer": "The :attribute value must be an integer",
|
||||
"float": "The :attribute value must be a float",
|
||||
"boolean": "The :attribute value field must be true or false",
|
||||
"same": "The :attribute value must be the same as field :field",
|
||||
"different": "The :attribute value must be different from field :field",
|
||||
"in": "The :attribute value is not in acceptable range",
|
||||
"not-in": "The :attribute value is not in acceptable range",
|
||||
"regex": "The :attribute value is invalid",
|
||||
internalDefaultRuleName: "The :attribute value is invalid",
|
||||
"required": "The {attribute} field is required",
|
||||
"required-if": "The {attribute} field is required",
|
||||
"required-unless": "The {attribute} field is required",
|
||||
"required-with": "The {attribute} field is required",
|
||||
"required-with-all": "The {attribute} field is required",
|
||||
"required-without": "The {attribute} field is required",
|
||||
"required-without-all": "The {attribute} field is required",
|
||||
"date": "The {attribute} value `{value}` is not a valid date",
|
||||
"datetime": "The {attribute} value `{value}` is not a valid datetime",
|
||||
"date-format": "The {attribute} value `{value}` does not match the format: {pattern}",
|
||||
"email": "The {attribute} value `{value}` is not a valid email address",
|
||||
"phone": "The {attribute} value `{value}` is not a valid phone number",
|
||||
"telephone": "The {attribute} value `{value}` is not a valid telephone number",
|
||||
"passport": "The {attribute} value `{value}` is not a valid passport format",
|
||||
"password": "The {attribute} value `{value}` is not a valid password format",
|
||||
"password2": "The {attribute} value `{value}` is not a valid password format",
|
||||
"password3": "The {attribute} value `{value}` is not a valid password format",
|
||||
"postcode": "The {attribute} value `{value}` is not a valid postcode format",
|
||||
"resident-id": "The {attribute} value `{value}` is not a valid resident id number",
|
||||
"bank-card": "The {attribute} value `{value}` is not a valid bank card number",
|
||||
"qq": "The {attribute} value `{value}` is not a valid QQ number",
|
||||
"ip": "The {attribute} value `{value}` is not a valid IP address",
|
||||
"ipv4": "The {attribute} value `{value}` is not a valid IPv4 address",
|
||||
"ipv6": "The {attribute} value `{value}` is not a valid IPv6 address",
|
||||
"mac": "The {attribute} value `{value}` is not a valid MAC address",
|
||||
"url": "The {attribute} value `{value}` is not a valid URL address",
|
||||
"domain": "The {attribute} value `{value}` is not a valid domain format",
|
||||
"length": "The {attribute} value `{value}` length must be between {min} and {max}",
|
||||
"min-length": "The {attribute} value `{value}` length must be equal or greater than {min}",
|
||||
"max-length": "The {attribute} value `{value}` length must be equal or lesser than {max}",
|
||||
"size": "The {attribute} value `{value}` length must be {size}",
|
||||
"between": "The {attribute} value `{value}` must be between {min} and {max}",
|
||||
"min": "The {attribute} value `{value}` must be equal or greater than {min}",
|
||||
"max": "The {attribute} value `{value}` must be equal or lesser than {max}",
|
||||
"json": "The {attribute} value `{value}` is not a valid JSON string",
|
||||
"xml": "The {attribute} value `{value}` is not a valid XML string",
|
||||
"array": "The {attribute} value `{value}` is not an array",
|
||||
"integer": "The {attribute} value `{value}` is not an integer",
|
||||
"boolean": "The {attribute} value `{value}` field must be true or false",
|
||||
"same": "The {attribute} value `{value}` must be the same as field {pattern}",
|
||||
"different": "The {attribute} value `{value}` must be different from field {pattern}",
|
||||
"in": "The {attribute} value `{value}` is not in acceptable range: {pattern}",
|
||||
"not-in": "The {attribute} value `{value}` must not be in range: {pattern}",
|
||||
"regex": "The {attribute} value `{value}` must be in regex of: {pattern}",
|
||||
internalDefaultRuleName: "The {attribute} value `{value}` is invalid",
|
||||
}
|
||||
// markedRuleMap defines all rules that are just marked rules which have neither functional meaning
|
||||
// nor error messages.
|
||||
|
||||
@ -9,7 +9,6 @@ package gvalid
|
||||
import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"strings"
|
||||
)
|
||||
@ -40,17 +39,12 @@ type validationError struct {
|
||||
|
||||
// newValidationError creates and returns a validation error.
|
||||
func newValidationError(code gcode.Code, rules []fieldRule, fieldRuleErrorMap map[string]map[string]error) *validationError {
|
||||
var (
|
||||
s string
|
||||
)
|
||||
for field, ruleErrorMap := range fieldRuleErrorMap {
|
||||
for rule, err := range ruleErrorMap {
|
||||
if !gerror.HasStack(err) {
|
||||
s = strings.Replace(err.Error(), ":attribute", field, -1)
|
||||
s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s)
|
||||
ruleErrorMap[rule] = gerror.NewOption(gerror.Option{
|
||||
Stack: false,
|
||||
Text: gstr.Trim(s),
|
||||
Text: gstr.Trim(err.Error()),
|
||||
Code: code,
|
||||
})
|
||||
}
|
||||
|
||||
@ -117,8 +117,9 @@ func (v *Validator) doCheckMap(ctx context.Context, params interface{}) Error {
|
||||
}); validatedError != nil {
|
||||
_, errorItem := validatedError.FirstItem()
|
||||
// ===========================================================
|
||||
// Only in map and struct validations, if value is nil or empty
|
||||
// string and has no required* rules, it clears the error message.
|
||||
// Only in map and struct validations:
|
||||
// If value is nil or empty string and has no required* rules,
|
||||
// it clears the error message.
|
||||
// ===========================================================
|
||||
if gconv.String(value) == "" {
|
||||
required := false
|
||||
@ -129,11 +130,6 @@ func (v *Validator) doCheckMap(ctx context.Context, params interface{}) Error {
|
||||
required = true
|
||||
break
|
||||
}
|
||||
// Custom rules are also required in default.
|
||||
if f := v.getRuleFunc(ruleKey); f != nil {
|
||||
required = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !required {
|
||||
continue
|
||||
@ -142,8 +138,8 @@ func (v *Validator) doCheckMap(ctx context.Context, params interface{}) Error {
|
||||
if _, ok := errorMaps[checkRuleItem.Name]; !ok {
|
||||
errorMaps[checkRuleItem.Name] = make(map[string]error)
|
||||
}
|
||||
for ruleKey, errorItemMsgMap := range errorItem {
|
||||
errorMaps[checkRuleItem.Name][ruleKey] = errorItemMsgMap
|
||||
for ruleKey, ruleError := range errorItem {
|
||||
errorMaps[checkRuleItem.Name][ruleKey] = ruleError
|
||||
}
|
||||
if v.bail {
|
||||
break
|
||||
|
||||
@ -178,7 +178,7 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
}
|
||||
|
||||
if _, ok := nameToRuleMap[name]; !ok {
|
||||
if _, ok := nameToRuleMap[fieldName]; ok {
|
||||
if _, ok = nameToRuleMap[fieldName]; ok {
|
||||
// If there's alias name,
|
||||
// use alias name as its key and remove the field name key.
|
||||
nameToRuleMap[name] = nameToRuleMap[fieldName]
|
||||
@ -254,10 +254,11 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
DataMap: inputParamMap,
|
||||
}); validatedError != nil {
|
||||
_, errorItem := validatedError.FirstItem()
|
||||
// ===================================================================
|
||||
// Only in map and struct validations, if value is nil or empty string
|
||||
// and has no required* rules, it clears the error message.
|
||||
// ===================================================================
|
||||
// ============================================================
|
||||
// Only in map and struct validations:
|
||||
// If value is nil or empty string and has no required* rules,
|
||||
// it clears the error message.
|
||||
// ============================================================
|
||||
if value == nil || gconv.String(value) == "" {
|
||||
required := false
|
||||
// rule => error
|
||||
@ -267,11 +268,6 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
required = true
|
||||
break
|
||||
}
|
||||
// Custom rules are also required in default.
|
||||
if f := v.getRuleFunc(ruleKey); f != nil {
|
||||
required = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !required {
|
||||
continue
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -68,12 +69,12 @@ func (v *Validator) doCheckValue(ctx context.Context, input doCheckValueInput) E
|
||||
msgArray = make([]string, 0)
|
||||
customMsgMap = make(map[string]string)
|
||||
)
|
||||
switch v := input.Messages.(type) {
|
||||
switch messages := input.Messages.(type) {
|
||||
case string:
|
||||
msgArray = strings.Split(v, "|")
|
||||
msgArray = strings.Split(messages, "|")
|
||||
default:
|
||||
for k, v := range gconv.Map(input.Messages) {
|
||||
customMsgMap[k] = gconv.String(v)
|
||||
for k, message := range gconv.Map(input.Messages) {
|
||||
customMsgMap[k] = gconv.String(message)
|
||||
}
|
||||
}
|
||||
// Handle the char '|' in the rule,
|
||||
@ -107,8 +108,8 @@ func (v *Validator) doCheckValue(ctx context.Context, input doCheckValueInput) E
|
||||
err error
|
||||
match = false // whether this rule is matched(has no error)
|
||||
results = ruleRegex.FindStringSubmatch(ruleItems[index]) // split single rule.
|
||||
ruleKey = strings.TrimSpace(results[1]) // rule name like "max" in rule "max: 6"
|
||||
rulePattern = strings.TrimSpace(results[2]) // rule value if any like "6" in rule:"max:6"
|
||||
ruleKey = gstr.Trim(results[1]) // rule key like "max" in rule "max: 6"
|
||||
rulePattern = gstr.Trim(results[2]) // rule pattern is like "6" in rule:"max:6"
|
||||
customRuleFunc RuleFunc
|
||||
)
|
||||
|
||||
@ -134,20 +135,30 @@ func (v *Validator) doCheckValue(ctx context.Context, input doCheckValueInput) E
|
||||
if customRuleFunc != nil {
|
||||
// It checks custom validation rules with most priority.
|
||||
message := v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
if err := customRuleFunc(ctx, RuleFuncInput{
|
||||
if err = customRuleFunc(ctx, RuleFuncInput{
|
||||
Rule: ruleItems[index],
|
||||
Message: message,
|
||||
Value: gvar.New(input.Value),
|
||||
Data: gvar.New(input.DataRaw),
|
||||
}); err != nil {
|
||||
match = false
|
||||
// The error should have stack info to indicate the error position.
|
||||
if !gerror.HasStack(err) {
|
||||
err = gerror.NewCodeSkip(gcode.CodeValidationFailed, 1, err.Error())
|
||||
}
|
||||
// The error should have error code that is `gcode.CodeValidationFailed`.
|
||||
if gerror.Code(err) == gcode.CodeNil {
|
||||
if e, ok := err.(*gerror.Error); ok {
|
||||
e.SetCode(gcode.CodeValidationFailed)
|
||||
}
|
||||
}
|
||||
ruleErrorMap[ruleKey] = err
|
||||
} else {
|
||||
match = true
|
||||
}
|
||||
} else {
|
||||
// It checks build-in validation rules if there's no custom rule.
|
||||
match, err = v.doCheckBuildInRules(
|
||||
match, err = v.doCheckSingleBuildInRules(
|
||||
ctx,
|
||||
doCheckBuildInRulesInput{
|
||||
Index: index,
|
||||
@ -171,6 +182,19 @@ func (v *Validator) doCheckValue(ctx context.Context, input doCheckValueInput) E
|
||||
if _, ok := ruleErrorMap[ruleKey]; !ok {
|
||||
ruleErrorMap[ruleKey] = errors.New(v.getErrorMessageByRule(ctx, ruleKey, customMsgMap))
|
||||
}
|
||||
|
||||
// Error variable replacement for error message.
|
||||
if err = ruleErrorMap[ruleKey]; !gerror.HasStack(err) {
|
||||
var s string
|
||||
s = gstr.ReplaceByMap(err.Error(), map[string]string{
|
||||
"{value}": gconv.String(input.Value),
|
||||
"{pattern}": rulePattern,
|
||||
"{attribute}": input.Name,
|
||||
})
|
||||
s, _ = gregex.ReplaceString(`\s{2,}`, ` `, s)
|
||||
ruleErrorMap[ruleKey] = errors.New(s)
|
||||
}
|
||||
|
||||
// If it is with error and there's bail rule,
|
||||
// it then does not continue validating for left rules.
|
||||
if hasBailRule {
|
||||
@ -192,16 +216,16 @@ func (v *Validator) doCheckValue(ctx context.Context, input doCheckValueInput) E
|
||||
}
|
||||
|
||||
type doCheckBuildInRulesInput struct {
|
||||
Index int
|
||||
Value interface{}
|
||||
RuleKey string
|
||||
RulePattern string
|
||||
RuleItems []string
|
||||
DataMap map[string]interface{}
|
||||
CustomMsgMap map[string]string
|
||||
Index int // Index of RuleKey in RuleItems.
|
||||
Value interface{} // Value to be validated.
|
||||
RuleKey string // RuleKey is like the "max" in rule "max: 6"
|
||||
RulePattern string // RulePattern is like "6" in rule:"max:6"
|
||||
RuleItems []string // RuleItems are all the rules that should be validated on single field, like: []string{"required", "min:1"}
|
||||
DataMap map[string]interface{} // Parameter map.
|
||||
CustomMsgMap map[string]string // Custom error message map.
|
||||
}
|
||||
|
||||
func (v *Validator) doCheckBuildInRules(ctx context.Context, input doCheckBuildInRulesInput) (match bool, err error) {
|
||||
func (v *Validator) doCheckSingleBuildInRules(ctx context.Context, input doCheckBuildInRulesInput) (match bool, err error) {
|
||||
valueStr := gconv.String(input.Value)
|
||||
switch input.RuleKey {
|
||||
// Required rules.
|
||||
@ -281,7 +305,6 @@ func (v *Validator) doCheckBuildInRules(ctx context.Context, input doCheckBuildI
|
||||
msg string
|
||||
)
|
||||
msg = v.getErrorMessageByRule(ctx, input.RuleKey, input.CustomMsgMap)
|
||||
msg = strings.Replace(msg, ":format", input.RulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
}
|
||||
|
||||
@ -296,7 +319,6 @@ func (v *Validator) doCheckBuildInRules(ctx context.Context, input doCheckBuildI
|
||||
if !match {
|
||||
var msg string
|
||||
msg = v.getErrorMessageByRule(ctx, input.RuleKey, input.CustomMsgMap)
|
||||
msg = strings.Replace(msg, ":field", input.RulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
}
|
||||
|
||||
@ -312,7 +334,6 @@ func (v *Validator) doCheckBuildInRules(ctx context.Context, input doCheckBuildI
|
||||
if !match {
|
||||
var msg string
|
||||
msg = v.getErrorMessageByRule(ctx, input.RuleKey, input.CustomMsgMap)
|
||||
msg = strings.Replace(msg, ":field", input.RulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
}
|
||||
|
||||
@ -450,13 +471,13 @@ func (v *Validator) doCheckBuildInRules(ctx context.Context, input doCheckBuildI
|
||||
|
||||
// Integer.
|
||||
case "integer":
|
||||
if _, err := strconv.Atoi(valueStr); err == nil {
|
||||
if _, err = strconv.Atoi(valueStr); err == nil {
|
||||
match = true
|
||||
}
|
||||
|
||||
// Float.
|
||||
case "float":
|
||||
if _, err := strconv.ParseFloat(valueStr, 10); err == nil {
|
||||
if _, err = strconv.ParseFloat(valueStr, 10); err == nil {
|
||||
match = true
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import "context"
|
||||
|
||||
// getErrorMessageByRule retrieves and returns the error message for specified rule.
|
||||
// It firstly retrieves the message from custom message map, and then checks i18n manager,
|
||||
// it returns the default error message if it's not found in custom message map or i18n manager.
|
||||
// it returns the default error message if it's not found in neither custom message map nor i18n manager.
|
||||
func (v *Validator) getErrorMessageByRule(ctx context.Context, ruleKey string, customMsgMap map[string]string) string {
|
||||
content := customMsgMap[ruleKey]
|
||||
if content != "" {
|
||||
|
||||
@ -41,8 +41,8 @@ func (v *Validator) checkLength(ctx context.Context, value, ruleKey, ruleVal str
|
||||
}
|
||||
if valueLen < min || valueLen > max {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":min", strconv.Itoa(min), -1)
|
||||
msg = strings.Replace(msg, ":max", strconv.Itoa(max), -1)
|
||||
msg = strings.Replace(msg, "{min}", strconv.Itoa(min), -1)
|
||||
msg = strings.Replace(msg, "{max}", strconv.Itoa(max), -1)
|
||||
return msg
|
||||
}
|
||||
|
||||
@ -50,21 +50,21 @@ func (v *Validator) checkLength(ctx context.Context, value, ruleKey, ruleVal str
|
||||
min, err := strconv.Atoi(ruleVal)
|
||||
if valueLen < min || err != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":min", strconv.Itoa(min), -1)
|
||||
msg = strings.Replace(msg, "{min}", strconv.Itoa(min), -1)
|
||||
}
|
||||
|
||||
case "max-length":
|
||||
max, err := strconv.Atoi(ruleVal)
|
||||
if valueLen > max || err != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":max", strconv.Itoa(max), -1)
|
||||
msg = strings.Replace(msg, "{max}", strconv.Itoa(max), -1)
|
||||
}
|
||||
|
||||
case "size":
|
||||
size, err := strconv.Atoi(ruleVal)
|
||||
if valueLen != size || err != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":size", strconv.Itoa(size), -1)
|
||||
msg = strings.Replace(msg, "{size}", strconv.Itoa(size), -1)
|
||||
}
|
||||
}
|
||||
return msg
|
||||
|
||||
@ -34,8 +34,8 @@ func (v *Validator) checkRange(ctx context.Context, value, ruleKey, ruleVal stri
|
||||
valueF, err := strconv.ParseFloat(value, 10)
|
||||
if valueF < min || valueF > max || err != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":min", strconv.FormatFloat(min, 'f', -1, 64), -1)
|
||||
msg = strings.Replace(msg, ":max", strconv.FormatFloat(max, 'f', -1, 64), -1)
|
||||
msg = strings.Replace(msg, "{min}", strconv.FormatFloat(min, 'f', -1, 64), -1)
|
||||
msg = strings.Replace(msg, "{max}", strconv.FormatFloat(max, 'f', -1, 64), -1)
|
||||
}
|
||||
|
||||
// Min value.
|
||||
@ -46,7 +46,7 @@ func (v *Validator) checkRange(ctx context.Context, value, ruleKey, ruleVal stri
|
||||
)
|
||||
if valueN < min || err1 != nil || err2 != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":min", strconv.FormatFloat(min, 'f', -1, 64), -1)
|
||||
msg = strings.Replace(msg, "{min}", strconv.FormatFloat(min, 'f', -1, 64), -1)
|
||||
}
|
||||
|
||||
// Max value.
|
||||
@ -57,7 +57,7 @@ func (v *Validator) checkRange(ctx context.Context, value, ruleKey, ruleVal stri
|
||||
)
|
||||
if valueN > max || err1 != nil || err2 != nil {
|
||||
msg = v.getErrorMessageByRule(ctx, ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":max", strconv.FormatFloat(max, 'f', -1, 64), -1)
|
||||
msg = strings.Replace(msg, "{max}", strconv.FormatFloat(max, 'f', -1, 64), -1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gvalid"
|
||||
"math"
|
||||
@ -26,8 +27,8 @@ func ExampleCheckMap() {
|
||||
"password2": "1234567",
|
||||
}
|
||||
rules := []string{
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在:min到:max之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在:min到:max之间|两次密码输入不相等",
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password@required|length:6,16|same{password}2#密码不能为空|密码长度应当在{min}到{max}之间|两次密码输入不相等",
|
||||
"password2@required|length:6,16#",
|
||||
}
|
||||
if e := gvalid.CheckMap(gctx.New(), params, rules); e != nil {
|
||||
@ -48,8 +49,8 @@ func ExampleCheckMap2() {
|
||||
"password2": "1234567",
|
||||
}
|
||||
rules := []string{
|
||||
"passport@length:6,16#账号不能为空|账号长度应当在:min到:max之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在:min到:max之间|两次密码输入不相等",
|
||||
"passport@length:6,16#账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在{min}到{max}之间|两次密码输入不相等",
|
||||
"password2@required|length:6,16#",
|
||||
}
|
||||
if e := gvalid.CheckMap(gctx.New(), params, rules); e != nil {
|
||||
@ -68,7 +69,7 @@ func ExampleCheckStruct() {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId string `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId string `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
@ -85,7 +86,7 @@ func ExampleCheckStruct2() {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId *gvar.Var `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId *gvar.Var `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
@ -102,7 +103,7 @@ func ExampleCheckStruct3() {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
@ -229,7 +230,7 @@ func ExampleValidator_CheckMap() {
|
||||
"password2": "required|length:6,16",
|
||||
}
|
||||
messages := map[string]interface{}{
|
||||
"passport": "账号不能为空|账号长度应当在:min到:max之间",
|
||||
"passport": "账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password": map[string]string{
|
||||
"required": "密码不能为空",
|
||||
"same": "两次密码输入不相等",
|
||||
@ -460,11 +461,13 @@ func ExampleValidator_Date() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Date3 value is not a valid date; The Date4 value is not a valid date; The Date5 value is not a valid date
|
||||
// The Date3 value `2021-Oct-31` is not a valid date
|
||||
// The Date4 value `2021 Octa 31` is not a valid date
|
||||
// The Date5 value `2021/Oct/31` is not a valid date
|
||||
}
|
||||
|
||||
func ExampleValidator_Datetime() {
|
||||
@ -485,11 +488,13 @@ func ExampleValidator_Datetime() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Date2 value is not a valid datetime; The Date3 value is not a valid datetime; The Date4 value is not a valid datetime
|
||||
// The Date2 value `2021-11-01 23:00` is not a valid datetime
|
||||
// The Date3 value `2021/11/01 23:00:00` is not a valid datetime
|
||||
// The Date4 value `2021/Dec/01 23:00:00` is not a valid datetime
|
||||
}
|
||||
|
||||
func ExampleValidator_DateFormat() {
|
||||
@ -510,11 +515,12 @@ func ExampleValidator_DateFormat() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Date2 value does not match the format Y-m-d; The Date4 value does not match the format Y-m-d H:i:s
|
||||
// The Date2 value `2021-11-01 23:00` does not match the format: Y-m-d
|
||||
// The Date4 value `2021-11-01 23:00` does not match the format: Y-m-d H:i:s
|
||||
}
|
||||
|
||||
func ExampleValidator_Email() {
|
||||
@ -535,11 +541,12 @@ func ExampleValidator_Email() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The MailAddr2 value must be a valid email address; The MailAddr4 value must be a valid email address
|
||||
// The MailAddr2 value `gf@goframe` is not a valid email address
|
||||
// The MailAddr4 value `gf#goframe.org` is not a valid email address
|
||||
}
|
||||
|
||||
func ExampleValidator_Phone() {
|
||||
@ -560,11 +567,13 @@ func ExampleValidator_Phone() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The PhoneNumber2 value must be a valid phone number; The PhoneNumber3 value must be a valid phone number; The PhoneNumber4 value must be a valid phone number
|
||||
// The PhoneNumber2 value `11578912345` is not a valid phone number
|
||||
// The PhoneNumber3 value `17178912345` is not a valid phone number
|
||||
// The PhoneNumber4 value `1357891234` is not a valid phone number
|
||||
}
|
||||
|
||||
func ExampleValidator_PhoneLoose() {
|
||||
@ -585,11 +594,12 @@ func ExampleValidator_PhoneLoose() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The PhoneNumber2 value must be a valid phone number; The PhoneNumber4 value must be a valid phone number
|
||||
// The PhoneNumber2 value `11578912345` is invalid
|
||||
// The PhoneNumber4 value `1357891234` is invalid
|
||||
}
|
||||
|
||||
func ExampleValidator_Telephone() {
|
||||
@ -610,11 +620,12 @@ func ExampleValidator_Telephone() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Telephone3 value must be a valid telephone number; The Telephone4 value must be a valid telephone number
|
||||
// The Telephone3 value `20-77542145` is not a valid telephone number
|
||||
// The Telephone4 value `775421451` is not a valid telephone number
|
||||
}
|
||||
|
||||
func ExampleValidator_Passport() {
|
||||
@ -635,11 +646,13 @@ func ExampleValidator_Passport() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Passport2 value is not a valid passport format; The Passport3 value is not a valid passport format; The Passport4 value is not a valid passport format
|
||||
// The Passport2 value `1356666` is not a valid passport format
|
||||
// The Passport3 value `goframe#` is not a valid passport format
|
||||
// The Passport4 value `gf` is not a valid passport format
|
||||
}
|
||||
|
||||
func ExampleValidator_Password() {
|
||||
@ -660,7 +673,7 @@ func ExampleValidator_Password() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Password2 value is not a valid passport format
|
||||
// The Password2 value `gofra` is not a valid password format
|
||||
}
|
||||
|
||||
func ExampleValidator_Password2() {
|
||||
@ -681,11 +694,13 @@ func ExampleValidator_Password2() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Password2 value is not a valid passport format; The Password3 value is not a valid passport format; The Password4 value is not a valid passport format
|
||||
// The Password2 value `gofra` is not a valid password format
|
||||
// The Password3 value `Goframe` is not a valid password format
|
||||
// The Password4 value `goframe123` is not a valid password format
|
||||
}
|
||||
|
||||
func ExampleValidator_Password3() {
|
||||
@ -704,11 +719,12 @@ func ExampleValidator_Password3() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Password2 value is not a valid passport format; The Password3 value is not a valid passport format
|
||||
// The Password2 value `gofra` is not a valid password format
|
||||
// The Password3 value `Goframe123` is not a valid password format
|
||||
}
|
||||
|
||||
func ExampleValidator_Postcode() {
|
||||
@ -727,11 +743,12 @@ func ExampleValidator_Postcode() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Postcode2 value is not a valid passport format; The Postcode3 value is not a valid passport format
|
||||
// The Postcode2 value `10000` is not a valid postcode format
|
||||
// The Postcode3 value `1000000` is not a valid postcode format
|
||||
}
|
||||
|
||||
func ExampleValidator_ResidentId() {
|
||||
@ -750,7 +767,7 @@ func ExampleValidator_ResidentId() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The ResidentID1 value is not a valid resident id number
|
||||
// The ResidentID1 value `320107199506285482` is not a valid resident id number
|
||||
}
|
||||
|
||||
func ExampleValidator_BankCard() {
|
||||
@ -769,7 +786,7 @@ func ExampleValidator_BankCard() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The BankCard1 value must be a valid bank card number
|
||||
// The BankCard1 value `6225760079930218` is not a valid bank card number
|
||||
}
|
||||
|
||||
func ExampleValidator_QQ() {
|
||||
@ -788,11 +805,12 @@ func ExampleValidator_QQ() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The QQ2 value must be a valid QQ number; The QQ3 value must be a valid QQ number
|
||||
// The QQ2 value `9999` is not a valid QQ number
|
||||
// The QQ3 value `514258412a` is not a valid QQ number
|
||||
}
|
||||
|
||||
func ExampleValidator_IP() {
|
||||
@ -813,11 +831,12 @@ func ExampleValidator_IP() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The IP3 value must be a valid IP address; The IP4 value must be a valid IP address
|
||||
// The IP3 value `520.255.255.255` is not a valid IP address
|
||||
// The IP4 value `ze80::812b:1158:1f43:f0d1` is not a valid IP address
|
||||
}
|
||||
|
||||
func ExampleValidator_IPV4() {
|
||||
@ -838,7 +857,7 @@ func ExampleValidator_IPV4() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The IP2 value must be a valid IPv4 address
|
||||
// The IP2 value `520.255.255.255` is not a valid IPv4 address
|
||||
}
|
||||
|
||||
func ExampleValidator_IPV6() {
|
||||
@ -859,7 +878,7 @@ func ExampleValidator_IPV6() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The IP2 value must be a valid IPv6 address
|
||||
// The IP2 value `ze80::812b:1158:1f43:f0d1` is not a valid IPv6 address
|
||||
}
|
||||
|
||||
func ExampleValidator_Mac() {
|
||||
@ -880,7 +899,7 @@ func ExampleValidator_Mac() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Mac2 value must be a valid MAC address
|
||||
// The Mac2 value `Z0-CC-6A-D6-B1-1A` is not a valid MAC address
|
||||
}
|
||||
|
||||
func ExampleValidator_Url() {
|
||||
@ -903,7 +922,7 @@ func ExampleValidator_Url() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The URL3 value must be a valid URL address
|
||||
// The URL3 value `ws://goframe.org` is not a valid URL address
|
||||
}
|
||||
|
||||
func ExampleValidator_Domain() {
|
||||
@ -924,11 +943,12 @@ func ExampleValidator_Domain() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Domain3 value must be a valid domain format; The Domain4 value must be a valid domain format
|
||||
// The Domain3 value `goframe#org` is not a valid domain format
|
||||
// The Domain4 value `1a.2b` is not a valid domain format
|
||||
}
|
||||
|
||||
func ExampleValidator_Size() {
|
||||
@ -949,7 +969,7 @@ func ExampleValidator_Size() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Size2 value length must be 5
|
||||
// The Size2 value `goframe` length must be 5
|
||||
}
|
||||
|
||||
func ExampleValidator_Length() {
|
||||
@ -970,7 +990,7 @@ func ExampleValidator_Length() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Length2 value length must be between 10 and 15
|
||||
// The Length2 value `goframe` length must be between 10 and 15
|
||||
}
|
||||
|
||||
func ExampleValidator_MinLength() {
|
||||
@ -991,7 +1011,7 @@ func ExampleValidator_MinLength() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The MinLength2 value length must be equal or greater than 8
|
||||
// The MinLength2 value `goframe` length must be equal or greater than 8
|
||||
}
|
||||
|
||||
func ExampleValidator_MaxLength() {
|
||||
@ -1012,7 +1032,7 @@ func ExampleValidator_MaxLength() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The MaxLength2 value length must be equal or lesser than 5
|
||||
// The MaxLength2 value `goframe` length must be equal or lesser than 5
|
||||
}
|
||||
|
||||
func ExampleValidator_Between() {
|
||||
@ -1033,11 +1053,12 @@ func ExampleValidator_Between() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Age2 value must be between 1 and 100; The Score2 value must be between 0 and 10
|
||||
// The Age2 value `101` must be between 1 and 100
|
||||
// The Score2 value `-0.5` must be between 0 and 10
|
||||
}
|
||||
|
||||
func ExampleValidator_Min() {
|
||||
@ -1058,11 +1079,12 @@ func ExampleValidator_Min() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Age1 value must be equal or greater than 100; The Score1 value must be equal or greater than 10
|
||||
// The Age1 value `50` must be equal or greater than 100
|
||||
// The Score1 value `9.8` must be equal or greater than 10
|
||||
}
|
||||
|
||||
func ExampleValidator_Max() {
|
||||
@ -1083,11 +1105,12 @@ func ExampleValidator_Max() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Age2 value must be equal or lesser than 100; The Score2 value must be equal or lesser than 10
|
||||
// The Age2 value `101` must be equal or lesser than 100
|
||||
// The Score2 value `10.1` must be equal or lesser than 10
|
||||
}
|
||||
|
||||
func ExampleValidator_Json() {
|
||||
@ -1108,7 +1131,7 @@ func ExampleValidator_Json() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The JSON2 value must be a valid JSON string
|
||||
// The JSON2 value `{"name":"goframe","author":"郭强","test"}` is not a valid JSON string
|
||||
}
|
||||
|
||||
func ExampleValidator_Integer() {
|
||||
@ -1127,11 +1150,12 @@ func ExampleValidator_Integer() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Float value must be an integer; The Str value must be an integer
|
||||
// The Float value `10.0` is not an integer
|
||||
// The Str value `goframe` is not an integer
|
||||
}
|
||||
|
||||
func ExampleValidator_Float() {
|
||||
@ -1154,7 +1178,7 @@ func ExampleValidator_Float() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Str value must be a float
|
||||
// The Str value `goframe` is invalid
|
||||
}
|
||||
|
||||
func ExampleValidator_Boolean() {
|
||||
@ -1179,11 +1203,12 @@ func ExampleValidator_Boolean() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Print(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Float value field must be true or false; The Str3 value field must be true or false
|
||||
// The Float value `10` field must be true or false
|
||||
// The Str3 value `goframe` field must be true or false
|
||||
}
|
||||
|
||||
func ExampleValidator_Same() {
|
||||
@ -1205,7 +1230,7 @@ func ExampleValidator_Same() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Password value must be the same as field Password2
|
||||
// The Password value `goframe.org` must be the same as field Password2
|
||||
}
|
||||
|
||||
func ExampleValidator_Different() {
|
||||
@ -1227,7 +1252,7 @@ func ExampleValidator_Different() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The OtherMailAddr value must be different from field MailAddr
|
||||
// The OtherMailAddr value `gf@goframe.org` must be different from field MailAddr
|
||||
}
|
||||
|
||||
func ExampleValidator_In() {
|
||||
@ -1249,7 +1274,7 @@ func ExampleValidator_In() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Gender value is not in acceptable range
|
||||
// The Gender value `3` is not in acceptable range: 0,1,2
|
||||
}
|
||||
|
||||
func ExampleValidator_NotIn() {
|
||||
@ -1271,7 +1296,7 @@ func ExampleValidator_NotIn() {
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The InvalidIndex value is not in acceptable range
|
||||
// The InvalidIndex value `1` must not be in range: -1,0,1
|
||||
}
|
||||
|
||||
func ExampleValidator_Regex() {
|
||||
@ -1289,9 +1314,10 @@ func ExampleValidator_Regex() {
|
||||
}
|
||||
)
|
||||
if err := g.Validator().CheckStruct(ctx, req); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Print(gstr.Join(err.Strings(), "\n"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// The Regex1 value is invalid; The Regex2 value is invalid
|
||||
// The Regex1 value `1234` must be in regex of: [1-9][0-9]{4,14}
|
||||
// The Regex2 value `01234` must be in regex of: [1-9][0-9]{4,14}
|
||||
}
|
||||
|
||||
@ -693,7 +693,7 @@ func Test_Length(t *testing.T) {
|
||||
func Test_MinLength(t *testing.T) {
|
||||
rule := "min-length:6"
|
||||
msgs := map[string]string{
|
||||
"min-length": "地址长度至少为:min位",
|
||||
"min-length": "地址长度至少为{min}位",
|
||||
}
|
||||
if m := gvalid.CheckValue(context.TODO(), "123456", rule, nil); m != nil {
|
||||
t.Error(m)
|
||||
@ -714,7 +714,7 @@ func Test_MinLength(t *testing.T) {
|
||||
func Test_MaxLength(t *testing.T) {
|
||||
rule := "max-length:6"
|
||||
msgs := map[string]string{
|
||||
"max-length": "地址长度至大为:max位",
|
||||
"max-length": "地址长度至大为{max}位",
|
||||
}
|
||||
if m := gvalid.CheckValue(context.TODO(), "12345", rule, nil); m != nil {
|
||||
t.Error(m)
|
||||
|
||||
@ -30,8 +30,8 @@ func Test_CheckMap1(t *testing.T) {
|
||||
t.Error("CheckMap校验失败")
|
||||
} else {
|
||||
t.Assert(len(m.Maps()), 2)
|
||||
t.Assert(m.Maps()["id"]["between"], "The id value must be between 1 and 100")
|
||||
t.Assert(m.Maps()["name"]["length"], "The name value length must be between 6 and 16")
|
||||
t.Assert(m.Maps()["id"]["between"], "The id value `0` must be between 1 and 100")
|
||||
t.Assert(m.Maps()["name"]["length"], "The name value `john` length must be between 6 and 16")
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -53,10 +53,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"name": "required|length:6,16",
|
||||
}
|
||||
msgs := gvalid.CustomMsg{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules, msgs); m == nil {
|
||||
@ -72,10 +72,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"name": "required|length:4,16",
|
||||
}
|
||||
msgs = map[string]interface{}{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules, msgs); m != nil {
|
||||
@ -91,10 +91,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"name": "",
|
||||
}
|
||||
msgs = map[string]interface{}{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules, msgs); m != nil {
|
||||
@ -110,10 +110,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"@required|length:4,16",
|
||||
}
|
||||
msgs = map[string]interface{}{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules2, msgs); m != nil {
|
||||
@ -129,10 +129,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"name@required|length:4,16#名称不能为空|",
|
||||
}
|
||||
msgs = map[string]interface{}{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules2, msgs); m != nil {
|
||||
@ -148,10 +148,10 @@ func Test_CheckMap2(t *testing.T) {
|
||||
"name@required|length:4,16#名称不能为空",
|
||||
}
|
||||
msgs = map[string]interface{}{
|
||||
"id": "ID不能为空|ID范围应当为:min到:max",
|
||||
"id": "ID不能为空|ID范围应当为{min}到{max}",
|
||||
"name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
}
|
||||
if m := gvalid.CheckMap(context.TODO(), kvmap, rules2, msgs); m != nil {
|
||||
@ -181,8 +181,8 @@ func Test_Sequence(t *testing.T) {
|
||||
"password2": "1234567",
|
||||
}
|
||||
rules := []string{
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在:min到:max之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在:min到:max之间|两次密码输入不相等",
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在{min}到{max}之间|两次密码输入不相等",
|
||||
"password2@required|length:6,16#",
|
||||
}
|
||||
err := gvalid.CheckMap(context.TODO(), params, rules)
|
||||
@ -221,8 +221,8 @@ func Test_Map_Bail(t *testing.T) {
|
||||
"password2": "1234567",
|
||||
}
|
||||
rules := []string{
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在:min到:max之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在:min到:max之间|两次密码输入不相等",
|
||||
"passport@required|length:6,16#账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在{min}到{max}之间|两次密码输入不相等",
|
||||
"password2@required|length:6,16#",
|
||||
}
|
||||
err := g.Validator().Bail().Rules(rules).CheckMap(ctx, params)
|
||||
@ -237,8 +237,8 @@ func Test_Map_Bail(t *testing.T) {
|
||||
"password2": "1234567",
|
||||
}
|
||||
rules := []string{
|
||||
"passport@bail|required|length:6,16#|账号不能为空|账号长度应当在:min到:max之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在:min到:max之间|两次密码输入不相等",
|
||||
"passport@bail|required|length:6,16#|账号不能为空|账号长度应当在{min}到{max}之间",
|
||||
"password@required|length:6,16|same:password2#密码不能为空|密码长度应当在{min}到{max}之间|两次密码输入不相等",
|
||||
"password2@required|length:6,16#",
|
||||
}
|
||||
err := g.Validator().Bail().Rules(rules).CheckMap(ctx, params)
|
||||
|
||||
@ -31,7 +31,7 @@ func Test_CheckStruct(t *testing.T) {
|
||||
msgs := map[string]interface{}{
|
||||
"Name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
"Age": "年龄为18到30周岁",
|
||||
}
|
||||
@ -52,7 +52,7 @@ func Test_CheckStruct(t *testing.T) {
|
||||
msgs := map[string]interface{}{
|
||||
"Name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
"Age": "年龄为18到30周岁",
|
||||
}
|
||||
@ -77,7 +77,7 @@ func Test_CheckStruct(t *testing.T) {
|
||||
msgs := map[string]interface{}{
|
||||
"Name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
"Age": "年龄为18到30周岁",
|
||||
}
|
||||
@ -102,7 +102,7 @@ func Test_CheckStruct(t *testing.T) {
|
||||
msgs := map[string]interface{}{
|
||||
"Name": map[string]string{
|
||||
"required": "名称不能为空",
|
||||
"length": "名称长度为:min到:max个字符",
|
||||
"length": "名称长度为{min}到{max}个字符",
|
||||
},
|
||||
"Age": "年龄为18到30周岁",
|
||||
}
|
||||
@ -336,7 +336,7 @@ func Test_CheckStruct_Optional(t *testing.T) {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId string `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId string `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
@ -349,7 +349,7 @@ func Test_CheckStruct_Optional(t *testing.T) {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId *gvar.Var `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId *gvar.Var `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
@ -362,7 +362,7 @@ func Test_CheckStruct_Optional(t *testing.T) {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
|
||||
@ -22,7 +22,7 @@ func Test_Map(t *testing.T) {
|
||||
val = "0.0.0"
|
||||
err = gvalid.CheckValue(context.TODO(), val, rule, nil)
|
||||
msg = map[string]string{
|
||||
"ipv4": "The value must be a valid IPv4 address",
|
||||
"ipv4": "The value `0.0.0` is not a valid IPv4 address",
|
||||
}
|
||||
)
|
||||
t.Assert(err.Map(), msg)
|
||||
@ -36,7 +36,7 @@ func Test_FirstString(t *testing.T) {
|
||||
val = "0.0.0"
|
||||
err = gvalid.CheckValue(context.TODO(), val, rule, nil)
|
||||
)
|
||||
t.Assert(err.FirstError(), "The value must be a valid IPv4 address")
|
||||
t.Assert(err.FirstError(), "The value `0.0.0` is not a valid IPv4 address")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ func TestValidator_I18n(t *testing.T) {
|
||||
type Params struct {
|
||||
Page int `v:"required|min:1 # page is required"`
|
||||
Size int `v:"required|between:1,100 # size is required"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between :min, :max"`
|
||||
ProjectId int `v:"between:1,10000 # project id must between {min}, {max}"`
|
||||
}
|
||||
obj := &Params{
|
||||
Page: 1,
|
||||
|
||||
@ -1,47 +1,47 @@
|
||||
"gf.gvalid.rule.required" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-if" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-unless" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-with" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-with-all" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-without" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-without-all" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.date" = ":attribute 日期格式不满足Y-m-d格式,例如: 2001-02-03"
|
||||
"gf.gvalid.rule.datetime" = ":attribute 日期格式不满足Y-m-d H:i:s格式,例如: 2001-02-03 12:00:00"
|
||||
"gf.gvalid.rule.date-format" = ":attribute 日期格式不满足:format"
|
||||
"gf.gvalid.rule.email" = ":attribute 邮箱地址格式不正确"
|
||||
"gf.gvalid.rule.phone" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.phone-loose" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.telephone" = ":attribute 电话号码格式不正确"
|
||||
"gf.gvalid.rule.passport" = ":attribute 账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间"
|
||||
"gf.gvalid.rule.password" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符"
|
||||
"gf.gvalid.rule.password2" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字"
|
||||
"gf.gvalid.rule.password3" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符"
|
||||
"gf.gvalid.rule.postcode" = ":attribute 邮政编码不正确"
|
||||
"gf.gvalid.rule.resident-id" = ":attribute 身份证号码格式不正确"
|
||||
"gf.gvalid.rule.bank-card" = ":attribute 银行卡号格式不正确"
|
||||
"gf.gvalid.rule.qq" = ":attribute QQ号码格式不正确"
|
||||
"gf.gvalid.rule.ip" = ":attribute IP地址格式不正确"
|
||||
"gf.gvalid.rule.ipv4" = ":attribute IPv4地址格式不正确"
|
||||
"gf.gvalid.rule.ipv6" = ":attribute IPv6地址格式不正确"
|
||||
"gf.gvalid.rule.mac" = ":attribute MAC地址格式不正确"
|
||||
"gf.gvalid.rule.url" = ":attribute URL地址格式不正确"
|
||||
"gf.gvalid.rule.domain" = ":attribute 域名格式不正确"
|
||||
"gf.gvalid.rule.length" = ":attribute 字段长度为:min到:max个字符"
|
||||
"gf.gvalid.rule.min-length" = ":attribute 字段最小长度为:min"
|
||||
"gf.gvalid.rule.max-length" = ":attribute 字段最大长度为:max"
|
||||
"gf.gvalid.rule.size" = ":attribute 字段长度必须为:size"
|
||||
"gf.gvalid.rule.between" = ":attribute 字段大小为:min到:max"
|
||||
"gf.gvalid.rule.min" = ":attribute 字段最小值为:min"
|
||||
"gf.gvalid.rule.max" = ":attribute 字段最大值为:max"
|
||||
"gf.gvalid.rule.json" = ":attribute 字段应当为JSON格式"
|
||||
"gf.gvalid.rule.xml" = ":attribute 字段应当为XML格式"
|
||||
"gf.gvalid.rule.array" = ":attribute 字段应当为数组"
|
||||
"gf.gvalid.rule.integer" = ":attribute 字段应当为整数"
|
||||
"gf.gvalid.rule.float" = ":attribute 字段应当为浮点数"
|
||||
"gf.gvalid.rule.boolean" = ":attribute 字段应当为布尔值"
|
||||
"gf.gvalid.rule.same" = ":attribute 字段值必须和:field相同"
|
||||
"gf.gvalid.rule.different" = ":attribute 字段值不能与:field相同"
|
||||
"gf.gvalid.rule.in" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.not-in" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.regex" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.__default__" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.required" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-if" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-unless" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-with" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-with-all" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-without" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-without-all" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.date" = "{attribute}字段值`{value}`日期格式不满足Y-m-d格式,例如: 2001-02-03"
|
||||
"gf.gvalid.rule.datetime" = "{attribute}字段值`{value}`日期格式不满足Y-m-d H:i:s格式,例如: 2001-02-03 12:00:00"
|
||||
"gf.gvalid.rule.date-format" = "{attribute}字段值`{value}`日期格式不满足{format}"
|
||||
"gf.gvalid.rule.email" = "{attribute}字段值`{value}`邮箱地址格式不正确"
|
||||
"gf.gvalid.rule.phone" = "{attribute}字段值`{value}`手机号码格式不正确"
|
||||
"gf.gvalid.rule.phone-loose" = "{attribute}字段值`{value}`手机号码格式不正确"
|
||||
"gf.gvalid.rule.telephone" = "{attribute}字段值`{value}`电话号码格式不正确"
|
||||
"gf.gvalid.rule.passport" = "{attribute}字段值`{value}`账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间"
|
||||
"gf.gvalid.rule.password" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符"
|
||||
"gf.gvalid.rule.password2" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字"
|
||||
"gf.gvalid.rule.password3" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符"
|
||||
"gf.gvalid.rule.postcode" = "{attribute}字段值`{value}`邮政编码不正确"
|
||||
"gf.gvalid.rule.resident-id" = "{attribute}字段值`{value}`身份证号码格式不正确"
|
||||
"gf.gvalid.rule.bank-card" = "{attribute}字段值`{value}`银行卡号格式不正确"
|
||||
"gf.gvalid.rule.qq" = "{attribute}字段值`{value}`QQ号码格式不正确"
|
||||
"gf.gvalid.rule.ip" = "{attribute}字段值`{value}`IP地址格式不正确"
|
||||
"gf.gvalid.rule.ipv4" = "{attribute}字段值`{value}`IPv4地址格式不正确"
|
||||
"gf.gvalid.rule.ipv6" = "{attribute}字段值`{value}`IPv6地址格式不正确"
|
||||
"gf.gvalid.rule.mac" = "{attribute}字段值`{value}`MAC地址格式不正确"
|
||||
"gf.gvalid.rule.url" = "{attribute}字段值`{value}`URL地址格式不正确"
|
||||
"gf.gvalid.rule.domain" = "{attribute}字段值`{value}`域名格式不正确"
|
||||
"gf.gvalid.rule.length" = "{attribute}字段值`{value}`字段长度应当为{min}到{max}个字符"
|
||||
"gf.gvalid.rule.min-length" = "{attribute}字段值`{value}`字段最小长度应当为{min}"
|
||||
"gf.gvalid.rule.max-length" = "{attribute}字段值`{value}`字段最大长度应当为{max}"
|
||||
"gf.gvalid.rule.size" = "{attribute}字段值`{value}`字段长度必须应当为{size}"
|
||||
"gf.gvalid.rule.between" = "{attribute}字段值`{value}`字段大小应当为{min}到{max}"
|
||||
"gf.gvalid.rule.min" = "{attribute}字段值`{value}`字段最小值应当为{min}"
|
||||
"gf.gvalid.rule.max" = "{attribute}字段值`{value}`字段最大值应当为{max}"
|
||||
"gf.gvalid.rule.json" = "{attribute}字段值`{value}`字段应当为JSON格式"
|
||||
"gf.gvalid.rule.xml" = "{attribute}字段值`{value}`字段应当为XML格式"
|
||||
"gf.gvalid.rule.array" = "{attribute}字段值`{value}`字段应当为数组"
|
||||
"gf.gvalid.rule.integer" = "{attribute}字段值`{value}`字段应当为整数"
|
||||
"gf.gvalid.rule.float" = "{attribute}字段值`{value}`字段应当为浮点数"
|
||||
"gf.gvalid.rule.boolean" = "{attribute}字段值`{value}`字段应当为布尔值"
|
||||
"gf.gvalid.rule.same" = "{attribute}字段值`{value}`字段值必须和{field}相同"
|
||||
"gf.gvalid.rule.different" = "{attribute}字段值`{value}`字段值不能与{field}相同"
|
||||
"gf.gvalid.rule.in" = "{attribute}字段值`{value}`字段值应当满足取值范围:{pattern}"
|
||||
"gf.gvalid.rule.not-in" = "{attribute}字段值`{value}`字段值不应当满足取值范围:{pattern}"
|
||||
"gf.gvalid.rule.regex" = "{attribute}字段值`{value}`字段值不满足规则:{pattern}"
|
||||
"gf.gvalid.rule.__default__" = "{attribute}字段值`{value}`字段值不合法"
|
||||
@ -1,47 +1,45 @@
|
||||
"gf.gvalid.rule.required" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-if" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-unless" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-with" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-with-all" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-without" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-without-all" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.date" = "The :attribute value is not a valid date"
|
||||
"gf.gvalid.rule.datetime" = "The :attribute value is not a valid datetime"
|
||||
"gf.gvalid.rule.date-format" = "The :attribute value does not match the format :format"
|
||||
"gf.gvalid.rule.email" = "The :attribute value must be a valid email address"
|
||||
"gf.gvalid.rule.phone" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.phone-loose" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.telephone" = "The :attribute value must be a valid telephone number"
|
||||
"gf.gvalid.rule.passport" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password2" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password3" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.postcode" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.resident-id" = "The :attribute value is not a valid resident id number"
|
||||
"gf.gvalid.rule.bank-card" = "The :attribute value must be a valid bank card number"
|
||||
"gf.gvalid.rule.qq" = "The :attribute value must be a valid QQ number"
|
||||
"gf.gvalid.rule.ip" = "The :attribute value must be a valid IP address"
|
||||
"gf.gvalid.rule.ipv4" = "The :attribute value must be a valid IPv4 address"
|
||||
"gf.gvalid.rule.ipv6" = "The :attribute value must be a valid IPv6 address"
|
||||
"gf.gvalid.rule.mac" = "The :attribute value must be a valid MAC address"
|
||||
"gf.gvalid.rule.url" = "The :attribute value must be a valid URL address"
|
||||
"gf.gvalid.rule.domain" = "The :attribute value must be a valid domain format"
|
||||
"gf.gvalid.rule.length" = "The :attribute value length must be between :min and :max"
|
||||
"gf.gvalid.rule.min-length" = "The :attribute value length must be equal or greater than :min"
|
||||
"gf.gvalid.rule.max-length" = "The :attribute value length must be equal or lesser than :max"
|
||||
"gf.gvalid.rule.size" = "The :attribute value length must be :size"
|
||||
"gf.gvalid.rule.between" = "The :attribute value must be between :min and :max"
|
||||
"gf.gvalid.rule.min" = "The :attribute value must be equal or greater than :min"
|
||||
"gf.gvalid.rule.max" = "The :attribute value must be equal or lesser than :max"
|
||||
"gf.gvalid.rule.json" = "The :attribute value must be a valid JSON string"
|
||||
"gf.gvalid.rule.xml" = "The :attribute value must be a valid XML string"
|
||||
"gf.gvalid.rule.array" = "The :attribute value must be an array"
|
||||
"gf.gvalid.rule.integer" = "The :attribute value must be an integer"
|
||||
"gf.gvalid.rule.float" = "The :attribute value must be a float"
|
||||
"gf.gvalid.rule.boolean" = "The :attribute value field must be true or false"
|
||||
"gf.gvalid.rule.same" = "The :attribute value must be the same as field :field"
|
||||
"gf.gvalid.rule.different" = "The :attribute value must be different from field :field"
|
||||
"gf.gvalid.rule.in" = "The :attribute value is not in acceptable range"
|
||||
"gf.gvalid.rule.not-in" = "The :attribute value is not in acceptable range"
|
||||
"gf.gvalid.rule.regex" = "The :attribute value is invalid"
|
||||
"gf.gvalid.rule.__default__" = "The :attribute value is invalid"
|
||||
"gf.gvalid.rule.required" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-if" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-unless" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-with" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-with-all" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-without" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-without-all" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.date" = "The {attribute} value `{value}` is not a valid date"
|
||||
"gf.gvalid.rule.datetime" = "The {attribute} value `{value}` is not a valid datetime"
|
||||
"gf.gvalid.rule.date-format" = "The {attribute} value `{value}` does not match the format: {pattern}"
|
||||
"gf.gvalid.rule.email" = "The {attribute} value `{value}` is not a valid email address"
|
||||
"gf.gvalid.rule.phone" = "The {attribute} value `{value}` is not a valid phone number"
|
||||
"gf.gvalid.rule.telephone" = "The {attribute} value `{value}` is not a valid telephone number"
|
||||
"gf.gvalid.rule.passport" = "The {attribute} value `{value}` is not a valid passport format"
|
||||
"gf.gvalid.rule.password" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.password2" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.password3" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.postcode" = "The {attribute} value `{value}` is not a valid postcode format"
|
||||
"gf.gvalid.rule.resident-id" = "The {attribute} value `{value}` is not a valid resident id number"
|
||||
"gf.gvalid.rule.bank-card" = "The {attribute} value `{value}` is not a valid bank card number"
|
||||
"gf.gvalid.rule.qq" = "The {attribute} value `{value}` is not a valid QQ number"
|
||||
"gf.gvalid.rule.ip" = "The {attribute} value `{value}` is not a valid IP address"
|
||||
"gf.gvalid.rule.ipv4" = "The {attribute} value `{value}` is not a valid IPv4 address"
|
||||
"gf.gvalid.rule.ipv6" = "The {attribute} value `{value}` is not a valid IPv6 address"
|
||||
"gf.gvalid.rule.mac" = "The {attribute} value `{value}` is not a valid MAC address"
|
||||
"gf.gvalid.rule.url" = "The {attribute} value `{value}` is not a valid URL address"
|
||||
"gf.gvalid.rule.domain" = "The {attribute} value `{value}` is not a valid domain format"
|
||||
"gf.gvalid.rule.length" = "The {attribute} value `{value}` length must be between {min} and {max}"
|
||||
"gf.gvalid.rule.min-length" = "The {attribute} value `{value}` length must be equal or greater than {min}"
|
||||
"gf.gvalid.rule.max-length" = "The {attribute} value `{value}` length must be equal or lesser than {max}"
|
||||
"gf.gvalid.rule.size" = "The {attribute} value `{value}` length must be {size}"
|
||||
"gf.gvalid.rule.between" = "The {attribute} value `{value}` must be between {min} and {max}"
|
||||
"gf.gvalid.rule.min" = "The {attribute} value `{value}` must be equal or greater than {min}"
|
||||
"gf.gvalid.rule.max" = "The {attribute} value `{value}` must be equal or lesser than {max}"
|
||||
"gf.gvalid.rule.json" = "The {attribute} value `{value}` is not a valid JSON string"
|
||||
"gf.gvalid.rule.xml" = "The {attribute} value `{value}` is not a valid XML string"
|
||||
"gf.gvalid.rule.array" = "The {attribute} value `{value}` is not an array"
|
||||
"gf.gvalid.rule.integer" = "The {attribute} value `{value}` is not an integer"
|
||||
"gf.gvalid.rule.boolean" = "The {attribute} value `{value}` field must be true or false"
|
||||
"gf.gvalid.rule.same" = "The {attribute} value `{value}` must be the same as field {pattern}"
|
||||
"gf.gvalid.rule.different" = "The {attribute} value `{value}` must be different from field {pattern}"
|
||||
"gf.gvalid.rule.in" = "The {attribute} value `{value}` is not in acceptable range: {pattern}"
|
||||
"gf.gvalid.rule.not-in" = "The {attribute} value `{value}` must not be in range: {pattern}"
|
||||
"gf.gvalid.rule.regex" = "The {attribute} value `{value}` must be in regex of: {pattern}"
|
||||
"gf.gvalid.rule.gf.gvalid.rule.__default__" = "The :attribute value `:value` is invalid"
|
||||
96
util/gvalid/testdata/i18n/cn/validation.toml
vendored
96
util/gvalid/testdata/i18n/cn/validation.toml
vendored
@ -1,49 +1,49 @@
|
||||
"gf.gvalid.rule.required" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-if" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-unless" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-with" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-with-all" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-without" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.required-without-all" = ":attribute 字段不能为空"
|
||||
"gf.gvalid.rule.date" = ":attribute 日期格式不正确"
|
||||
"gf.gvalid.rule.date-format" = ":attribute 日期格式不满足:format"
|
||||
"gf.gvalid.rule.email" = ":attribute 邮箱地址格式不正确"
|
||||
"gf.gvalid.rule.phone" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.phone-loose" = ":attribute 手机号码格式不正确"
|
||||
"gf.gvalid.rule.telephone" = ":attribute 电话号码格式不正确"
|
||||
"gf.gvalid.rule.passport" = ":attribute 账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间"
|
||||
"gf.gvalid.rule.password" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符"
|
||||
"gf.gvalid.rule.password2" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字"
|
||||
"gf.gvalid.rule.password3" = ":attribute 密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符"
|
||||
"gf.gvalid.rule.postcode" = ":attribute 邮政编码不正确"
|
||||
"gf.gvalid.rule.resident-id" = ":attribute 身份证号码格式不正确"
|
||||
"gf.gvalid.rule.bank-card" = ":attribute 银行卡号格式不正确"
|
||||
"gf.gvalid.rule.qq" = ":attribute QQ号码格式不正确"
|
||||
"gf.gvalid.rule.ip" = ":attribute IP地址格式不正确"
|
||||
"gf.gvalid.rule.ipv4" = ":attribute IPv4地址格式不正确"
|
||||
"gf.gvalid.rule.ipv6" = ":attribute IPv6地址格式不正确"
|
||||
"gf.gvalid.rule.mac" = ":attribute MAC地址格式不正确"
|
||||
"gf.gvalid.rule.url" = ":attribute URL地址格式不正确"
|
||||
"gf.gvalid.rule.domain" = ":attribute 域名格式不正确"
|
||||
"gf.gvalid.rule.length" = ":attribute 字段长度为:min到:max个字符"
|
||||
"gf.gvalid.rule.min-length" = ":attribute 字段最小长度为:min"
|
||||
"gf.gvalid.rule.max-length" = ":attribute 字段最大长度为:max"
|
||||
"gf.gvalid.rule.size" = ":attribute 字段长度为必须为:size"
|
||||
"gf.gvalid.rule.between" = ":attribute 字段大小为:min到:max"
|
||||
"gf.gvalid.rule.min" = ":attribute 字段最小值为:min"
|
||||
"gf.gvalid.rule.max" = ":attribute 字段最大值为:max"
|
||||
"gf.gvalid.rule.json" = ":attribute 字段应当为JSON格式"
|
||||
"gf.gvalid.rule.xml" = ":attribute 字段应当为XML格式"
|
||||
"gf.gvalid.rule.array" = ":attribute 字段应当为数组"
|
||||
"gf.gvalid.rule.integer" = ":attribute 字段应当为整数"
|
||||
"gf.gvalid.rule.float" = ":attribute 字段应当为浮点数"
|
||||
"gf.gvalid.rule.boolean" = ":attribute 字段应当为布尔值"
|
||||
"gf.gvalid.rule.same" = ":attribute 字段值必须和:field相同"
|
||||
"gf.gvalid.rule.different" = ":attribute 字段值不能与:field相同"
|
||||
"gf.gvalid.rule.in" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.not-in" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.regex" = ":attribute 字段值不合法"
|
||||
"gf.gvalid.rule.__default__" = ":attribute 字段值不合法"
|
||||
|
||||
"gf.gvalid.rule.required" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-if" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-unless" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-with" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-with-all" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-without" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.required-without-all" = "{attribute}字段不能为空"
|
||||
"gf.gvalid.rule.date" = "{attribute}字段值`{value}`日期格式不满足Y-m-d格式,例如: 2001-02-03"
|
||||
"gf.gvalid.rule.datetime" = "{attribute}字段值`{value}`日期格式不满足Y-m-d H:i:s格式,例如: 2001-02-03 12:00:00"
|
||||
"gf.gvalid.rule.date-format" = "{attribute}字段值`{value}`日期格式不满足{format}"
|
||||
"gf.gvalid.rule.email" = "{attribute}字段值`{value}`邮箱地址格式不正确"
|
||||
"gf.gvalid.rule.phone" = "{attribute}字段值`{value}`手机号码格式不正确"
|
||||
"gf.gvalid.rule.phone-loose" = "{attribute}字段值`{value}`手机号码格式不正确"
|
||||
"gf.gvalid.rule.telephone" = "{attribute}字段值`{value}`电话号码格式不正确"
|
||||
"gf.gvalid.rule.passport" = "{attribute}字段值`{value}`账号格式不合法,必需以字母开头,只能包含字母、数字和下划线,长度在6~18之间"
|
||||
"gf.gvalid.rule.password" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符"
|
||||
"gf.gvalid.rule.password2" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母和数字"
|
||||
"gf.gvalid.rule.password3" = "{attribute}字段值`{value}`密码格式不合法,密码格式为任意6-18位的可见字符,必须包含大小写字母、数字和特殊字符"
|
||||
"gf.gvalid.rule.postcode" = "{attribute}字段值`{value}`邮政编码不正确"
|
||||
"gf.gvalid.rule.resident-id" = "{attribute}字段值`{value}`身份证号码格式不正确"
|
||||
"gf.gvalid.rule.bank-card" = "{attribute}字段值`{value}`银行卡号格式不正确"
|
||||
"gf.gvalid.rule.qq" = "{attribute}字段值`{value}`QQ号码格式不正确"
|
||||
"gf.gvalid.rule.ip" = "{attribute}字段值`{value}`IP地址格式不正确"
|
||||
"gf.gvalid.rule.ipv4" = "{attribute}字段值`{value}`IPv4地址格式不正确"
|
||||
"gf.gvalid.rule.ipv6" = "{attribute}字段值`{value}`IPv6地址格式不正确"
|
||||
"gf.gvalid.rule.mac" = "{attribute}字段值`{value}`MAC地址格式不正确"
|
||||
"gf.gvalid.rule.url" = "{attribute}字段值`{value}`URL地址格式不正确"
|
||||
"gf.gvalid.rule.domain" = "{attribute}字段值`{value}`域名格式不正确"
|
||||
"gf.gvalid.rule.length" = "{attribute}字段值`{value}`字段长度应当为{min}到{max}个字符"
|
||||
"gf.gvalid.rule.min-length" = "{attribute}字段值`{value}`字段最小长度应当为{min}"
|
||||
"gf.gvalid.rule.max-length" = "{attribute}字段值`{value}`字段最大长度应当为{max}"
|
||||
"gf.gvalid.rule.size" = "{attribute}字段值`{value}`字段长度必须应当为{size}"
|
||||
"gf.gvalid.rule.between" = "{attribute}字段值`{value}`字段大小应当为{min}到{max}"
|
||||
"gf.gvalid.rule.min" = "{attribute}字段值`{value}`字段最小值应当为{min}"
|
||||
"gf.gvalid.rule.max" = "{attribute}字段值`{value}`字段最大值应当为{max}"
|
||||
"gf.gvalid.rule.json" = "{attribute}字段值`{value}`字段应当为JSON格式"
|
||||
"gf.gvalid.rule.xml" = "{attribute}字段值`{value}`字段应当为XML格式"
|
||||
"gf.gvalid.rule.array" = "{attribute}字段值`{value}`字段应当为数组"
|
||||
"gf.gvalid.rule.integer" = "{attribute}字段值`{value}`字段应当为整数"
|
||||
"gf.gvalid.rule.float" = "{attribute}字段值`{value}`字段应当为浮点数"
|
||||
"gf.gvalid.rule.boolean" = "{attribute}字段值`{value}`字段应当为布尔值"
|
||||
"gf.gvalid.rule.same" = "{attribute}字段值`{value}`字段值必须和{field}相同"
|
||||
"gf.gvalid.rule.different" = "{attribute}字段值`{value}`字段值不能与{field}相同"
|
||||
"gf.gvalid.rule.in" = "{attribute}字段值`{value}`字段值应当满足取值范围:{pattern}"
|
||||
"gf.gvalid.rule.not-in" = "{attribute}字段值`{value}`字段值不应当满足取值范围:{pattern}"
|
||||
"gf.gvalid.rule.regex" = "{attribute}字段值`{value}`字段值不满足规则:{pattern}"
|
||||
"gf.gvalid.rule.__default__" = "{attribute}字段值`{value}`字段值不合法"
|
||||
"CustomMessage" = "自定义错误"
|
||||
"project id must between :min, :max" = "项目ID必须大于等于:min并且要小于等于:max"
|
||||
"project id must between {min}, {max}" = "项目ID必须大于等于{min}并且要小于等于{max}"
|
||||
91
util/gvalid/testdata/i18n/en/validation.toml
vendored
91
util/gvalid/testdata/i18n/en/validation.toml
vendored
@ -1,46 +1,45 @@
|
||||
"gf.gvalid.rule.required" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-if" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-unless" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-with" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-with-all" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-without" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.required-without-all" = "The :attribute field is required"
|
||||
"gf.gvalid.rule.date" = "The :attribute value is not a valid date"
|
||||
"gf.gvalid.rule.date-format" = "The :attribute value does not match the format :format"
|
||||
"gf.gvalid.rule.email" = "The :attribute value must be a valid email address"
|
||||
"gf.gvalid.rule.phone" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.phone-loose" = "The :attribute value must be a valid phone number"
|
||||
"gf.gvalid.rule.telephone" = "The :attribute value must be a valid telephone number"
|
||||
"gf.gvalid.rule.passport" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password2" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.password3" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.postcode" = "The :attribute value is not a valid passport format"
|
||||
"gf.gvalid.rule.resident-id" = "The :attribute value is not a valid resident id number"
|
||||
"gf.gvalid.rule.bank-card" = "The :attribute value must be a valid bank card number"
|
||||
"gf.gvalid.rule.qq" = "The :attribute value must be a valid QQ number"
|
||||
"gf.gvalid.rule.ip" = "The :attribute value must be a valid IP address"
|
||||
"gf.gvalid.rule.ipv4" = "The :attribute value must be a valid IPv4 address"
|
||||
"gf.gvalid.rule.ipv6" = "The :attribute value must be a valid IPv6 address"
|
||||
"gf.gvalid.rule.mac" = "The :attribute value must be a valid MAC address"
|
||||
"gf.gvalid.rule.url" = "The :attribute value must be a valid URL address"
|
||||
"gf.gvalid.rule.domain" = "The :attribute value must be a valid domain format"
|
||||
"gf.gvalid.rule.length" = "The :attribute value length must be between :min and :max"
|
||||
"gf.gvalid.rule.min-length" = "The :attribute value length must be equal or greater than :min"
|
||||
"gf.gvalid.rule.max-length" = "The :attribute value length must be equal or lesser than :max"
|
||||
"gf.gvalid.rule.size" = "The :attribute value length must be :size"
|
||||
"gf.gvalid.rule.between" = "The :attribute value must be between :min and :max"
|
||||
"gf.gvalid.rule.min" = "The :attribute value must be equal or greater than :min"
|
||||
"gf.gvalid.rule.max" = "The :attribute value must be equal or lesser than :max"
|
||||
"gf.gvalid.rule.json" = "The :attribute value must be a valid JSON string"
|
||||
"gf.gvalid.rule.xml" = "The :attribute value must be a valid XML string"
|
||||
"gf.gvalid.rule.array" = "The :attribute value must be an array"
|
||||
"gf.gvalid.rule.integer" = "The :attribute value must be an integer"
|
||||
"gf.gvalid.rule.float" = "The :attribute value must be a float"
|
||||
"gf.gvalid.rule.boolean" = "The :attribute value field must be true or false"
|
||||
"gf.gvalid.rule.same" = "The :attribute value must be the same as field :field"
|
||||
"gf.gvalid.rule.different" = "The :attribute value must be different from field :field"
|
||||
"gf.gvalid.rule.in" = "The :attribute value is not in acceptable range"
|
||||
"gf.gvalid.rule.not-in" = "The :attribute value is not in acceptable range"
|
||||
"gf.gvalid.rule.regex" = "The :attribute value is invalid"
|
||||
"gf.gvalid.rule.__default__" = "The :attribute value is invalid"
|
||||
"gf.gvalid.rule.required" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-if" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-unless" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-with" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-with-all" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-without" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.required-without-all" = "The {attribute} field is required"
|
||||
"gf.gvalid.rule.date" = "The {attribute} value `{value}` is not a valid date"
|
||||
"gf.gvalid.rule.datetime" = "The {attribute} value `{value}` is not a valid datetime"
|
||||
"gf.gvalid.rule.date-format" = "The {attribute} value `{value}` does not match the format: {pattern}"
|
||||
"gf.gvalid.rule.email" = "The {attribute} value `{value}` is not a valid email address"
|
||||
"gf.gvalid.rule.phone" = "The {attribute} value `{value}` is not a valid phone number"
|
||||
"gf.gvalid.rule.telephone" = "The {attribute} value `{value}` is not a valid telephone number"
|
||||
"gf.gvalid.rule.passport" = "The {attribute} value `{value}` is not a valid passport format"
|
||||
"gf.gvalid.rule.password" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.password2" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.password3" = "The {attribute} value `{value}` is not a valid password format"
|
||||
"gf.gvalid.rule.postcode" = "The {attribute} value `{value}` is not a valid postcode format"
|
||||
"gf.gvalid.rule.resident-id" = "The {attribute} value `{value}` is not a valid resident id number"
|
||||
"gf.gvalid.rule.bank-card" = "The {attribute} value `{value}` is not a valid bank card number"
|
||||
"gf.gvalid.rule.qq" = "The {attribute} value `{value}` is not a valid QQ number"
|
||||
"gf.gvalid.rule.ip" = "The {attribute} value `{value}` is not a valid IP address"
|
||||
"gf.gvalid.rule.ipv4" = "The {attribute} value `{value}` is not a valid IPv4 address"
|
||||
"gf.gvalid.rule.ipv6" = "The {attribute} value `{value}` is not a valid IPv6 address"
|
||||
"gf.gvalid.rule.mac" = "The {attribute} value `{value}` is not a valid MAC address"
|
||||
"gf.gvalid.rule.url" = "The {attribute} value `{value}` is not a valid URL address"
|
||||
"gf.gvalid.rule.domain" = "The {attribute} value `{value}` is not a valid domain format"
|
||||
"gf.gvalid.rule.length" = "The {attribute} value `{value}` length must be between {min} and {max}"
|
||||
"gf.gvalid.rule.min-length" = "The {attribute} value `{value}` length must be equal or greater than {min}"
|
||||
"gf.gvalid.rule.max-length" = "The {attribute} value `{value}` length must be equal or lesser than {max}"
|
||||
"gf.gvalid.rule.size" = "The {attribute} value `{value}` length must be {size}"
|
||||
"gf.gvalid.rule.between" = "The {attribute} value `{value}` must be between {min} and {max}"
|
||||
"gf.gvalid.rule.min" = "The {attribute} value `{value}` must be equal or greater than {min}"
|
||||
"gf.gvalid.rule.max" = "The {attribute} value `{value}` must be equal or lesser than {max}"
|
||||
"gf.gvalid.rule.json" = "The {attribute} value `{value}` is not a valid JSON string"
|
||||
"gf.gvalid.rule.xml" = "The {attribute} value `{value}` is not a valid XML string"
|
||||
"gf.gvalid.rule.array" = "The {attribute} value `{value}` is not an array"
|
||||
"gf.gvalid.rule.integer" = "The {attribute} value `{value}` is not an integer"
|
||||
"gf.gvalid.rule.boolean" = "The {attribute} value `{value}` field must be true or false"
|
||||
"gf.gvalid.rule.same" = "The {attribute} value `{value}` must be the same as field {pattern}"
|
||||
"gf.gvalid.rule.different" = "The {attribute} value `{value}` must be different from field {pattern}"
|
||||
"gf.gvalid.rule.in" = "The {attribute} value `{value}` is not in acceptable range: {pattern}"
|
||||
"gf.gvalid.rule.not-in" = "The {attribute} value `{value}` must not be in range: {pattern}"
|
||||
"gf.gvalid.rule.regex" = "The {attribute} value `{value}` must be in regex of: {pattern}"
|
||||
"gf.gvalid.rule.gf.gvalid.rule.__default__" = "The :attribute value `:value` is invalid"
|
||||
@ -1,4 +1,4 @@
|
||||
package gf
|
||||
|
||||
const VERSION = "v2.0.0-alpha"
|
||||
const VERSION = "v2.0.0-beta"
|
||||
const AUTHORS = "john<john@goframe.org>"
|
||||
|
||||
Reference in New Issue
Block a user