feat(Go-Tool):2020/12/14:添加validator.v8源码解析和使用示例

This commit is contained in:
Huangzj
2020-12-14 15:15:58 +08:00
parent 23d7d6e226
commit fa31b23cca
51 changed files with 4619 additions and 1662 deletions
+17 -17
View File
@@ -5,30 +5,30 @@ import "reflect"
// Iterator is an alias for function to iterate over data.
type Iterator func() (item interface{}, ok bool)
// Query is the type returned from query functions. It can be iterated manually
// as shown in the example.
// Query is the type returned from query functions.
// It can be iterated manually as shown in the example.
type Query struct {
Iterate func() Iterator
}
// KeyValue is a type that is used to iterate over a map (if query is created
// from a map). This type is also used by ToMap() method to output result of a
// query into a map.
// KeyValue is a type that is used to iterate over a map
// (if query is created from a map). This type is also used by
// ToMap() method to output result of a query into a map.
type KeyValue struct {
Key interface{}
Value interface{}
}
// Iterable is an interface that has to be implemented by a custom collection in
// order to work with linq.
// Iterable is an interface that has to be implemented by a
// custom collection in order to work with linq.
type Iterable interface {
Iterate() Iterator
}
// From initializes a linq query with passed slice, array or map as the source.
// String, channel or struct implementing Iterable interface can be used as an
// input. In this case From delegates it to FromString, FromChannel and
// FromIterable internally.
// From initializes a linq query with passed slice, array or map
// as the source. String, channel or struct implementing Iterable
// interface can be used as an input. In this case From delegates it
// to FromString, FromChannel and FromIterable internally.
func From(source interface{}) Query {
src := reflect.ValueOf(source)
@@ -84,8 +84,8 @@ func From(source interface{}) Query {
}
}
// FromChannel initializes a linq query with passed channel, linq iterates over
// channel until it is closed.
// FromChannel initializes a linq query with passed channel,
// linq iterates over channel until it is closed.
func FromChannel(source <-chan interface{}) Query {
return Query{
Iterate: func() Iterator {
@@ -97,8 +97,8 @@ func FromChannel(source <-chan interface{}) Query {
}
}
// FromString initializes a linq query with passed string, linq iterates over
// runes of string.
// FromString initializes a linq query with passed string,
// linq iterates over runes of string.
func FromString(source string) Query {
runes := []rune(source)
len := len(runes)
@@ -120,8 +120,8 @@ func FromString(source string) Query {
}
}
// FromIterable initializes a linq query with custom collection passed. This
// collection has to implement Iterable interface, linq iterates over items,
// FromIterable initializes a linq query with custom collection passed.
// This collection has to implement Iterable interface, linq iterates over items,
// that has to implement Comparable interface or be basic types.
func FromIterable(source Iterable) Query {
return Query{