[feat] 依赖调整 git.fsdpf.net/go/contracts => git.fsdpf.net/go/req

This commit is contained in:
what 2024-05-08 22:32:51 +08:00
parent 028bc603cf
commit 1d047e071b
9 changed files with 99 additions and 92 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/contracts/support"
"git.fsdpf.net/go/db"
"github.com/samber/lo"
@ -50,19 +50,19 @@ func (this Condition) IsAlwaysRight() bool {
flag := []bool{}
for _, expr := range this.exprs {
if expr.GetOperator() != contracts.ConditionOperator_EQ {
if expr.GetOperator() != contracts.EQ {
flag = append(flag, false)
continue
}
if expr.GetTokenType() != contracts.ConditionTokenType_SQL {
if expr.GetTokenType() != contracts.SQL {
flag = append(flag, false)
continue
}
eRight := fmt.Sprintf("%s.%s", expr.GetFieldResource(), expr.GetField()) == strings.ReplaceAll(expr.GetTokenName(), "`", "")
if this.typ == contracts.ConditionType_OR && eRight {
if this.typ == contracts.OR && eRight {
return true
}
@ -72,7 +72,7 @@ func (this Condition) IsAlwaysRight() bool {
for _, cond := range this.childrens {
cRight := cond.IsAlwaysRight()
if this.typ == contracts.ConditionType_OR && cRight {
if this.typ == contracts.OR && cRight {
return true
}
@ -87,7 +87,7 @@ func (this Condition) IsAlwaysRight() bool {
}
// 生成 SQL 语句
func (this Condition) ToSql(m contracts.ModelParam) db.Expression {
func (this Condition) ToSql(m contracts.ConditionTokenValue) db.Expression {
conditions := []string{}
// 表达式
for _, item := range this.exprs {
@ -106,16 +106,16 @@ func (this Condition) ToSql(m contracts.ModelParam) db.Expression {
sql := strings.Join(conditions, " "+string(this.Type())+" ")
if sql == "" {
if this.parent == nil && this.Type() == contracts.ConditionType_OR {
if this.parent == nil && this.Type() == contracts.OR {
return db.Raw("false")
} else if this.parent == nil && this.Type() == contracts.ConditionType_AND {
} else if this.parent == nil && this.Type() == contracts.AND {
return db.Raw("true")
}
return db.Raw("")
}
// 包裹 SQL, 避免语法表达错误
if this.parent == nil || this.Type() == contracts.ConditionType_OR {
if this.parent == nil || this.Type() == contracts.OR {
sql = "(" + sql + ")"
}
@ -151,14 +151,14 @@ func (this *Condition) SetMatchPrefix(prefix string) contracts.Condition {
return this
}
func (this Condition) GetFieldsValue(m contracts.ModelParam, isWithResource bool) (result map[string]any) {
func (this Condition) GetFieldsValue(m contracts.ConditionTokenValue, isWithResource bool) (result map[string]any) {
if this.IsEmpty() {
return
}
// 表达式
for _, item := range this.exprs {
if item.GetOperator() != contracts.ConditionOperator_EQ {
if item.GetOperator() != contracts.EQ {
continue
}

View File

@ -6,7 +6,7 @@ import (
"reflect"
"strings"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/db"
"github.com/samber/lo"
"github.com/spf13/cast"
@ -46,7 +46,7 @@ func (this *ConditionExpr) AppendTo(c contracts.Condition) {
this.parent = c
}
func (this ConditionExpr) ToSql(m contracts.ModelParam) db.Expression {
func (this ConditionExpr) ToSql(m contracts.ConditionTokenValue) db.Expression {
first := "`" + this.fieldResource + "`.`" + this.field + "`"
if strings.Contains(this.field, "->") {
@ -65,24 +65,24 @@ func (this ConditionExpr) ToSql(m contracts.ModelParam) db.Expression {
//
secondary := ""
switch operator {
case contracts.ConditionOperator_IS_NULL:
case contracts.ConditionOperator_IS_NOT_NULL:
case contracts.IS_NULL:
case contracts.IS_NOT_NULL:
secondary = ""
case contracts.ConditionOperator_EQ, contracts.ConditionOperator_NE,
contracts.ConditionOperator_GT, contracts.ConditionOperator_GE,
contracts.ConditionOperator_LT, contracts.ConditionOperator_LE,
contracts.ConditionOperator_REGEXP, contracts.ConditionOperator_NOT_REGEXP:
case contracts.EQ, contracts.NE,
contracts.GT, contracts.GE,
contracts.LT, contracts.LE,
contracts.REGEXP, contracts.NOT_REGEXP:
if this.GetTokenType() == contracts.ConditionTokenType_SQL {
if this.GetTokenType() == contracts.SQL {
secondary = value
} else {
secondary = "'" + strings.Trim(value, "'") + "'"
}
case contracts.ConditionOperator_LIKE, contracts.ConditionOperator_NOT_LIKE:
case contracts.LIKE, contracts.NOT_LIKE:
secondary = "'%" + strings.Trim(value, "'") + "%'"
case contracts.ConditionOperator_IN, contracts.ConditionOperator_NOT_IN:
case contracts.IN, contracts.NOT_IN:
secondary = "(" + lo.Ternary(value == "", "''", value) + ")"
}
@ -117,8 +117,8 @@ func (this ConditionExpr) GetTokenType() contracts.ConditionTokenType {
return this.tokenType
}
func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
if this.GetTokenType() == contracts.ConditionTokenType_SQL {
func (this *ConditionExpr) GetTokenSqlValue(m contracts.ConditionTokenValue) string {
if this.GetTokenType() == contracts.SQL {
return this.token
}
@ -141,8 +141,8 @@ func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
}
// 强制使用 in
if this.operator == contracts.ConditionOperator_EQ {
this.operator = contracts.ConditionOperator_IN
if this.operator == contracts.EQ {
this.operator = contracts.IN
}
return strings.Join(aStr, ", ")
@ -154,16 +154,16 @@ func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
}
}
func (this ConditionExpr) GetTokenValue(m contracts.ModelParam) any {
func (this ConditionExpr) GetTokenValue(m contracts.ConditionTokenValue) any {
switch this.GetTokenType() {
case contracts.ConditionTokenType_PARAM:
case contracts.PARAM:
if this.matchPrefix != "" {
return m.GetParam(fmt.Sprintf("%s.%s", this.matchPrefix, this.token)).Value()
}
return m.GetParam(this.token).Value()
case contracts.ConditionTokenType_STRING:
case contracts.STRING:
return this.token
case contracts.ConditionTokenType_FUNC:
case contracts.FUNC:
switch this.token {
case "UserID":
return m.GetGlobalParamsUser().ID()
@ -182,12 +182,12 @@ func (this ConditionExpr) GetTokenValue(m contracts.ModelParam) any {
return nil
}
func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ModelParam) bool {
func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ConditionTokenValue) bool {
if !this.ignoreEmptyParma {
return false
}
if this.tokenType != contracts.ConditionTokenType_PARAM {
if this.tokenType != contracts.PARAM {
return false
}

View File

@ -6,9 +6,9 @@ import (
"reflect"
"strings"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/contracts/support"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/req"
"github.com/samber/lo"
"github.com/spf13/cast"
)
@ -33,8 +33,8 @@ func init() {
type Engine[T any] struct {
code string
opts engineOptions
g contracts.GlobalParams
def func(data T, g contracts.GlobalParams) error
g req.GlobalParams
def func(data T, g req.GlobalParams) error
predicates []*EngineCase[T]
}
@ -43,18 +43,18 @@ func (this Engine[T]) GetCode() string {
}
// 公共参数
func (this *Engine[T]) SetGlobalParams(g contracts.GlobalParams) *Engine[T] {
func (this *Engine[T]) SetGlobalParams(g req.GlobalParams) *Engine[T] {
this.g = g
return this
}
func (this *Engine[T]) Case(cond contracts.Condition, cb func(data T, g contracts.GlobalParams) error) *Engine[T] {
func (this *Engine[T]) Case(cond contracts.Condition, cb func(data T, g req.GlobalParams) error) *Engine[T] {
this.predicates = append(this.predicates, &EngineCase[T]{cond, cb})
return this
}
// 基础条件
func (this *Engine[T]) Default(cb func(data T, g contracts.GlobalParams) error) *Engine[T] {
func (this *Engine[T]) Default(cb func(data T, g req.GlobalParams) error) *Engine[T] {
this.def = cb
return this
}
@ -169,7 +169,7 @@ func (this *Engine[T]) Execute(data T) error {
}
if this.g == nil {
this.g = support.NewGlobalParam(`{}`, nil)
this.g = req.NewGlobalParam(`{}`, nil)
}
param := &EngineParam{this.g}
@ -220,6 +220,6 @@ func New[T any](table string, opt ...EngineOption) *Engine[T] {
return &Engine[T]{
code: table,
opts: opts,
g: support.NewGlobalParam("", nil),
g: req.NewGlobalParam("", nil),
}
}

View File

@ -1,16 +1,17 @@
package engine
import (
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/req"
)
type EngineCase[T any] struct {
predicate contracts.Condition
cb func(data T, g contracts.GlobalParams) error
cb func(data T, g req.GlobalParams) error
}
func (this EngineCase[T]) ToSql(param contracts.ModelParam) db.Expression {
func (this EngineCase[T]) ToSql(param contracts.ConditionTokenValue) db.Expression {
if this.predicate == nil || this.predicate.IsEmpty() {
return db.Raw("NULL")
}
@ -18,6 +19,6 @@ func (this EngineCase[T]) ToSql(param contracts.ModelParam) db.Expression {
return this.predicate.ToSql(param)
}
func (this EngineCase[T]) Execute(data T, g contracts.GlobalParams) error {
func (this EngineCase[T]) Execute(data T, g req.GlobalParams) error {
return this.cb(data, g)
}

View File

@ -1,15 +1,17 @@
package engine
import "git.fsdpf.net/go/contracts"
import (
"git.fsdpf.net/go/req"
)
type EngineParam struct {
data contracts.GlobalParams
data req.GlobalParams
}
func (this EngineParam) GetParam(k string) contracts.GlobalParams {
func (this EngineParam) GetParam(k string) req.GlobalParams {
return this.data.Get(k)
}
func (this EngineParam) GetGlobalParamsUser() contracts.User {
func (this EngineParam) GetGlobalParamsUser() req.User {
return this.data.User()
}

View File

@ -4,8 +4,8 @@ import (
"testing"
"git.fsdpf.net/go/condition"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/contracts/support"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/req"
)
type TestTable struct {
@ -21,23 +21,23 @@ type TestTable struct {
func TestEngine(t *testing.T) {
engine := Engine[any]{
code: "TestTable",
g: support.NewGlobalParam(`{"age": 30}`, nil),
g: req.NewGlobalParam(`{"age": 30}`, nil),
}
cond1 := condition.New(contracts.ConditionType_AND, "条件1")
cond1 := condition.New(contracts.AND, "条件1")
cond1.SetExpr(condition.NewConditionExpr(
"TestTable", "age", "age",
contracts.ConditionOperator_EQ, contracts.ConditionTokenType_PARAM,
contracts.EQ, contracts.PARAM,
false, "", "",
))
engine.Case(cond1, func(data any, g contracts.GlobalParams) error {
engine.Case(cond1, func(data any, g req.GlobalParams) error {
t.Log("cond1", data)
return nil
})
engine.Default(func(data any, g contracts.GlobalParams) error {
engine.Default(func(data any, g req.GlobalParams) error {
t.Log("default", data)
return nil
})
@ -60,43 +60,43 @@ func TestEngine(t *testing.T) {
func TestRelationEngine(t *testing.T) {
engine := Engine[any]{
code: "TestTable",
g: support.NewGlobalParam(`{"age": 30}`, nil),
g: req.NewGlobalParam(`{"age": 30}`, nil),
opts: engineOptions{
debug: false,
relations: []string{"TestTableA"},
},
}
cond1 := condition.New(contracts.ConditionType_AND, "条件1").
cond1 := condition.New(contracts.AND, "条件1").
SetExpr(condition.NewConditionExpr(
"TestTable", "age", "age",
contracts.ConditionOperator_EQ, contracts.ConditionTokenType_PARAM,
contracts.EQ, contracts.PARAM,
false, "", "",
))
engine.Case(cond1, func(data any, g contracts.GlobalParams) error {
engine.Case(cond1, func(data any, g req.GlobalParams) error {
t.Log("cond1", data)
return nil
})
cond2 := condition.New(contracts.ConditionType_OR, "条件2").
cond2 := condition.New(contracts.OR, "条件2").
SetExpr(condition.NewConditionExpr(
"TestTableA", "age", "age",
contracts.ConditionOperator_EQ, contracts.ConditionTokenType_PARAM,
contracts.EQ, contracts.PARAM,
false, "", "",
)).
SetExpr(condition.NewConditionExpr(
"TestTable", "age", "age",
contracts.ConditionOperator_EQ, contracts.ConditionTokenType_PARAM,
contracts.EQ, contracts.PARAM,
false, "", "",
))
engine.Case(cond2, func(data any, g contracts.GlobalParams) error {
engine.Case(cond2, func(data any, g req.GlobalParams) error {
t.Log("cond2", data)
return nil
})
engine.Default(func(data any, g contracts.GlobalParams) error {
engine.Default(func(data any, g req.GlobalParams) error {
t.Log("default", data)
return nil
})

16
go.mod
View File

@ -1,20 +1,22 @@
module git.fsdpf.net/go/condition
go 1.19
go 1.21
toolchain go1.21.5
require (
git.fsdpf.net/go/contracts v0.0.0-20240327025936-ee4b5fe3c6fe
git.fsdpf.net/go/db v0.0.0-20230621051209-5740d112407f
github.com/samber/lo v1.38.1
github.com/spf13/cast v1.5.1
git.fsdpf.net/go/db v0.0.0-20230731125324-11651ea6640b
git.fsdpf.net/go/req v0.0.0-20240508133526-672fc634ef20
github.com/samber/lo v1.39.0
github.com/spf13/cast v1.6.0
)
require (
github.com/bufbuild/protocompile v0.4.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-chi/chi v1.5.4 // indirect
github.com/go-chi/chi/v5 v5.0.10 // indirect
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/protobuf v1.5.2 // indirect
@ -39,7 +41,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect

36
go.sum
View File

@ -36,14 +36,12 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.fsdpf.net/go/contracts v0.0.0-20230719062509-d506eeb0b432 h1:H7PItbuhXzJjnQiAzWHitT/SW/ucgYDaQBJCRbh543k=
git.fsdpf.net/go/contracts v0.0.0-20230719062509-d506eeb0b432/go.mod h1:gaSvU1UPH6M8Q2ZRW316VAIbDQQWG+5TV1jNrl1QvCA=
git.fsdpf.net/go/contracts v0.0.0-20231227143841-17ee1779bc43 h1:JbFTBiAhkue/NDdSUvoLAoCSKlObJhQiwO+q5CqliCE=
git.fsdpf.net/go/contracts v0.0.0-20231227143841-17ee1779bc43/go.mod h1:F7FKRPH8zPGvaH58WmZSKeRKV0SwCz9PxreqisJQ5rE=
git.fsdpf.net/go/contracts v0.0.0-20240327025936-ee4b5fe3c6fe h1:LT/04X/uaECp813gX9HzLE3/yRDaEeSL/oow460jPFY=
git.fsdpf.net/go/contracts v0.0.0-20240327025936-ee4b5fe3c6fe/go.mod h1:F7FKRPH8zPGvaH58WmZSKeRKV0SwCz9PxreqisJQ5rE=
git.fsdpf.net/go/db v0.0.0-20230621051209-5740d112407f h1:H+/H6j+hyFMgSy+tUNmymRy7/PWQRjjp8qY/DrhwrsY=
git.fsdpf.net/go/db v0.0.0-20230621051209-5740d112407f/go.mod h1:397Sdx1cJS0OlHtTX1bVl//9k3Xn0Klnc6jC4MAkb6w=
git.fsdpf.net/go/db v0.0.0-20230731125324-11651ea6640b h1:fRgWNOQ9dAYuUZHQ24oi1XqRbJIcJvZGbnQDaAKI7IY=
git.fsdpf.net/go/db v0.0.0-20230731125324-11651ea6640b/go.mod h1:397Sdx1cJS0OlHtTX1bVl//9k3Xn0Klnc6jC4MAkb6w=
git.fsdpf.net/go/req v0.0.0-20240508133526-672fc634ef20 h1:PhjRtac2r0Vn1WBBzhRhz4//bJhHgkf/SHZe3mQYPto=
git.fsdpf.net/go/req v0.0.0-20240508133526-672fc634ef20/go.mod h1:S+p7t3XclKxsvaXQng7AMmqEGq11FSnMzxOtv1z8JUw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
@ -68,13 +66,12 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@ -123,6 +120,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@ -159,9 +157,11 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A=
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
github.com/lestrrat-go/blackmagic v1.0.0 h1:XzdxDbuQTz0RZZEmdU7cnQxUtFUzgCSPq8RCz4BxIi4=
@ -190,14 +190,15 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/samber/do v1.6.0 h1:Jy/N++BXINDB6lAx5wBlbpHlUdl0FKpLWgGEV9YWqaU=
github.com/samber/do v1.6.0/go.mod h1:DWqBvumy8dyb2vEnYZE7D7zaVEB64J45B0NjTlY/M4k=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@ -219,8 +220,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
@ -336,6 +337,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -1,7 +1,7 @@
package condition
import (
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/condition/contracts"
"git.fsdpf.net/go/contracts/base"
)
@ -12,9 +12,9 @@ func NewConditionByRes(items []base.ResCondition, describe string) (root contrac
for _, item := range items {
switch item.Type {
case "and":
conditions[item.Id] = &Condition{typ: contracts.ConditionType_AND}
conditions[item.Id] = &Condition{typ: contracts.AND}
case "or":
conditions[item.Id] = &Condition{typ: contracts.ConditionType_OR}
conditions[item.Id] = &Condition{typ: contracts.OR}
case "expr":
conditions[item.Id] = &ConditionExpr{
field: item.Column,