func MatchV(v interface{}, f *Filter) bool { match := false /* rv0 := reflect.ValueOf(v) if rv0.Kind() == reflect.Ptr { rv0 = reflect.Indirect(rv0) } rv1 := reflect.ValueOf(f.Value) if rv1.Kind()==reflect.Ptr{ rv1=reflect.Indirect(rv1) } */ if toolkit.HasMember([]interface{}{FilterOpEqual, FilterOpNoEqual, FilterOpGt, FilterOpGte, FilterOpLt, FilterOpLte}, f.Op) { return Compare(v, f.Value, f.Op) } else if f.Op == FilterOpIn { var values []interface{} toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values) return toolkit.HasMember(values, v) } else if f.Op == FilterOpNin { var values []interface{} toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values) return !toolkit.HasMember(values, v) } return match }
func MatchV(v interface{}, f *Filter) bool { match := false /* rv0 := reflect.ValueOf(v) if rv0.Kind() == reflect.Ptr { rv0 = reflect.Indirect(rv0) } rv1 := reflect.ValueOf(f.Value) if rv1.Kind()==reflect.Ptr{ rv1=reflect.Indirect(rv1) } */ //toolkit.Println("MatchV: ", f.Op, v, f.Value) if toolkit.HasMember([]string{FilterOpEqual, FilterOpNoEqual, FilterOpGt, FilterOpGte, FilterOpLt, FilterOpLte}, f.Op) { return toolkit.Compare(v, f.Value, f.Op) } else if f.Op == FilterOpIn { var values []interface{} toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values) return toolkit.HasMember(values, v) } else if f.Op == FilterOpNin { var values []interface{} toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values) return !toolkit.HasMember(values, v) } else if f.Op == FilterOpContains { var values []interface{} var b bool toolkit.FromBytes(toolkit.ToBytes(f.Value, ""), "", &values) for _, val := range values { // value := toolkit.Sprintf(".*%s.*", val.(string)) // b, _ = regexp.Match(value, []byte(v.(string))) r := regexp.MustCompile(`(?i)` + val.(string)) b = r.Match([]byte(v.(string))) if b { return true } } } else if f.Op == FilterOpStartWith || f.Op == FilterOpEndWith { value := "" if f.Op == FilterOpStartWith { value = toolkit.Sprintf("^%s.*$", f.Value) } else { value = toolkit.Sprintf("^.*%s$", f.Value) } cond, _ := regexp.Match(value, []byte(v.(string))) return cond } return match }
func (c *Coordinator) UpdateMetadata(in toolkit.M) *toolkit.Result { result := toolkit.NewResult() keys := []string{} bs := in.Get("keys", []byte{}).([]byte) toolkit.FromBytes(bs, "gob", &keys) return result }
func (a *Client) Connect(address string, secret string, userid string) error { //("Connecting to %s@%s \n", userid, address) a.UserID = userid client, e := rpc.Dial("tcp", address) if e != nil { return errorlib.Error(packageName, objClient, "Connect", "["+address+"] Unable to connect: "+e.Error()) } a.client = client a.LoginDate = time.Now().UTC() r := a.Call("addsession", toolkit.M{}.Set("auth_secret", secret).Set("auth_referenceid", a.UserID)) if r.Status != toolkit.Status_OK { return errors.New("[" + address + "] Connect: " + r.Message + " User:"******"gob", &m) a.address = address a.sessionID = m.GetString("referenceid") a.secret = m.GetString("secret") return nil }
func TestStorageGet(t *testing.T) { skipIfClientNil(t) in := toolkit.M{} in.Set("key", "dataku") getResult := client.Call("get", in) if getResult.Status != toolkit.Status_OK { t.Errorf(getResult.Message) return } data := []int{} e := toolkit.FromBytes(getResult.Data.([]byte), "", &data) if e != nil { t.Errorf("Unable to decode: " + e.Error()) } fmt.Println("Result received: %s \n", toolkit.JsonString(data)) total := int(crowd.From(data).Sum(nil)) if total != totalInt { t.Errorf("Wrong summation expecting %d got %d", totalInt, total) } }