比较两个相同类型的结构

Situation I am in:

I am writing an api testing tool. And want to compare the actual api results with an expected result.

  1. I am accessing a json API and parsing the result into a struct (api_result)
  2. I load a predefined json from local storage and also parse it into the same type of struct (expected_result)
  3. Now I want to compare them

What I want to archive:

These two structs of the type result should be compared based on the fields in expected_result.

Example

  • expected_result has the fields b1,b2,b4
  • api_result has the fields b2,b4,b5,b6

Now I want to only compare the fields b1,b2,b4 and also only if they are not empty (0,"",nil).

The other fields that are in api_result are not important.

Tried so far

I already dug into reflect.DeepEqual() and then into go-cmp. But with both is the problem that the compare functions are (or have to be) symmetric (func(x,y)==func(y,x)).

With that symetry I can't differntiate between the two compared items.

Thanks a lot for your ideas and help!