rencalo770 / gengine

Rule Engine for Golang
Other
433 stars 70 forks source link

Evaluate MapVarValue Only support directly-Pointer-Map, directly-Pointer-Slice and directly-Pointer-Array or Map, Slice and Array in Pointer-Struct #6

Closed nekohor closed 4 years ago

nekohor commented 4 years ago

    type MapTypeWithKeyStr  map[string]int
    type MapTypeWithKeyInt  map[int]string

   //define
    type MS struct {
        MII *map[int]int
        MSI MapTypeWithKeyStr
        MIS MapTypeWithKeyInt  
    }

    //init
    MS := &MS{
        MII: &map[int]int{1: 1},
        MSI: MapTypeWithKeyStr{"hello": 1},
        MIS: MapTypeWithKeyInt {1: "hello"},
    }
rencalo770 commented 4 years ago

yes, golang‘s feature decides it! if programmer write it rightly, When user configure rules, they are unaware of this.

there is an example in golang :

type Person struct {
      Age int
}

// it is not a ptr, when you call this func to change Person's Age, you will  change nothing!
func (p Person)SetAge( a int){
     p.Age = a
}
nekohor commented 4 years ago

What you mean is that the barren programming language Golang lead to the compromise of user who have to use struct signature and method to wrap the abstraction of business.

rencalo770 commented 4 years ago

in some conditions, almost what it means. but you can not only use struct ,but also you can directly inject functions or data without struct to do what you want,such as follow example: WeChatWorkScreenshot_a40719c3-894b-4180-aa2e-441c311a8b3a

nekohor commented 4 years ago

Aoligei