Documentation ¶
Overview ¶
------------------------------------------------------------------------------ 用于比较两个对象的函数集。 Golang 不是弱类型语言、不是解释型语言。但弱类型语言、解释型语言也有他们的优点,比如能判断出 1 == "1" 等类型不同、但实际含义相同的表达式。 同时,解释型语言可以很方便的在运行时判断两个变量是否相等,比如: let a = 1; let b = "1"; if evel("$a == $b") { ... } 这样的特性很灵活、有时候会很高效。 此函数集实现类似的功能,可以通过 Compare(a, b interface{}, opr string, option int) 来比较两个对象。函数内部判断他们可能的类型,尝试将他们类型统一后再进行操作符运算。
该函数的使用场景,参见 jsonValidator 类库。 ------------------------------------------------------------------------------
Index ¶
- Constants
- func Compare(a, b interface{}, opr Operator, options ...int) (bool, error)
- func CompareBool(a, b bool, opr Operator) (bool, error)
- func CompareFloat(a, b float64, opr Operator) (ok bool, err error)
- func CompareInt(a, b int64, opr Operator) (bool, error)
- func CompareNil(a interface{}, opr Operator) (bool, error)
- func CompareString(a, b string, opr Operator, options ...int) (ok bool, err error)
- func CompareUint(a, b uint64, opr Operator) (ok bool, err error)
- type Operator
Constants ¶
const ( Option_None = iota Option_CaseSensitive = 1 Option_CaseInsensitive = 2 )
Variables ¶
This section is empty.
Functions ¶
func CompareBool ¶
比较两个 bool 变量。 opr 指定比较操作符, eq|ueq
func CompareFloat ¶
比较两个 float 变量。 opr 指定比较操作符, eq|ueq|gt|egt|lt|elt
func CompareInt ¶
比较两个 int 变量。 opr 指定比较操作符, eq|ueq|gt|egt|lt|elt
func CompareNil ¶
func CompareString ¶
比较两个 string 变量。 opr 指定比较操作符, eq|ueq|gt|egt|lt|elt
Types ¶
type Operator ¶
type Operator string
const ( Operator_Exist Operator = "exist" Operator_Eq Operator = "eq" Operator_Ueq Operator = "ueq" Operator_Gt Operator = "gt" Operator_Egt Operator = "egt" Operator_Lt Operator = "lt" Operator_Elt Operator = "elt" Operator_Like Operator = "like" Operator_NotLike Operator = "not-like" Operator_Regex Operator = "regex" Operator_Contains Operator = "contains" Operator_NotContains Operator = "not-contains" Operator_In Operator = "in" Operator_NotIn Operator = "not-in" Operator_Empty Operator = "empty" Operator_NotEmpty Operator = "not-empty" )