RedemptionC commented on issue #2011:
URL: 
https://github.com/apache/apisix-dashboard/issues/2011#issuecomment-891885644


   @nic-chen 
   it seems we can compare them using this code snippet:
   ```go
   func AreEqualJSON(s1, s2 string) (bool, error) {
        fmt.Printf("compare:\ncache: %s\nand\netcd: %s\n", s1, s2)
        var o1 interface{}
        var o2 interface{}
   
        var err error
        err = json.Unmarshal([]byte(s1), &o1)
        if err != nil {
                return false, fmt.Errorf("Error mashalling string 1 :: %s", 
err.Error())
        }
        err = json.Unmarshal([]byte(s2), &o2)
        if err != nil {
                return false, fmt.Errorf("Error mashalling string 2 :: %s", 
err.Error())
        }
   
        return reflect.DeepEqual(o1, o2), nil
   }
   ```
   in the store.go/List(),we get the value from cache and etcd,value returned 
by etcd.go/Get is already string(json format)
   we just need to parse value from cache into json string
   then use the function above
   and this is the output:
   ```
   consumer.List is called                                                      
                                                          
   in list                                                                      
                                                          
   compare:                                                                     
                                                          
   cache: 
{"username":"red","plugins":{"key-auth":{"key":"key-of-john"}},"create_time":1627738877,"update_time":1627738933}
   and
   etcd: 
{"username":"red","plugins":{"key-auth":{"key":"key-of-john"}},"update_time":1627738933,"create_time":1627738877}
   cache content and etcd content on this key(/apisix/consumers/red) is the 
same: true
   ......
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to