Skip to main content

Tutorial Intro

Some practical tools、 algorithms written in Go

Docs Version Dropdown

p2c grpc balancer

// example
func test() {
cc, err := grpc.Dial(r.Scheme()+":///test.server",
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, p2c.Name)))
if err != nil {
t.Fatalf("failed to dial: %v", err)
}
defer cc.Close()
}

ast rule engine

supported operator

  • comparator: > >= < <= ==

  • bitwise: & | ^

  • bitwiseShift: << >>

  • additive: + -

  • multiplicative: * / %

  • prefix: !(NOT) -(NEGATE)

  • logic: && ||

  • func call: ( ) , func(do func call with build in function and custom function)

  • params type: Ident Number String Bool array, struct (DO Not support func )

  • recursive params call with .: map.mapKey.mapKey.arrayIndex.structFiledName (foo.bar.2.Name)

  • Link

// example
import (
. "github.com/sado0823/go-kitx/kit/rule"
)

func main(){

expr := `foo + 1 > bar`

param := map[string]interface{}{
"foo": 5,
"bar": 6,
}

res, err := Do(context.Background(), expr, param)
if err != nil {
panic(err)
}
}