valueEqual checks if two values are equal. It supports comparing string, int, float64, bool, and []byte values.
(value1 interface{}, value2 interface{})
| 541 | // valueEqual checks if two values are equal. |
| 542 | // It supports comparing string, int, float64, bool, and []byte values. |
| 543 | func (l *ListStructure) valueEqual(value1 interface{}, value2 interface{}) bool { |
| 544 | type1 := reflect.TypeOf(value1) |
| 545 | type2 := reflect.TypeOf(value2) |
| 546 | |
| 547 | // If the types are not the same, the values are not equal |
| 548 | if type1 != type2 { |
| 549 | return false |
| 550 | } |
| 551 | |
| 552 | // Compare based on type |
| 553 | switch type1.Kind() { |
| 554 | case reflect.String: |
| 555 | return value1.(string) == value2.(string) |
| 556 | case reflect.Int: |
| 557 | return value1.(int) == value2.(int) |
| 558 | case reflect.Float64: |
| 559 | return value1.(float64) == value2.(float64) |
| 560 | case reflect.Bool: |
| 561 | return value1.(bool) == value2.(bool) |
| 562 | case reflect.Slice: |
| 563 | // Special case for []byte |
| 564 | if type1.Elem().Kind() == reflect.Uint8 { |
| 565 | return bytes.Equal(value1.([]byte), value2.([]byte)) |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | // For other types, return false |
| 570 | return false |
| 571 | } |
| 572 | |
| 573 | // getListFromDB retrieves data from the database. When isKeyCanNotExist is true, it returns an empty slice if the key doesn't exist instead of an error. |
| 574 | func (l *ListStructure) getListFromDB(key string, isKeyCanNotExist bool) (*list, int64, error) { |