mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
fix(db): fix marshalling code so that we're compatible with the existing db (#6286)
* special handling for non-json types * added tests for json MarshalObject * another attempt * Fix marshal/unmarshal code for VERSION bucket * use short form * don't discard err * fix the json_test.go * remove duplicate string * added uuid tests * updated case for strings Co-authored-by: zees-dev <dev.786zshan@gmail.com>
This commit is contained in:
parent
187b66f5cb
commit
33a29159d2
2 changed files with 140 additions and 1 deletions
|
@ -8,12 +8,29 @@ import (
|
|||
|
||||
// MarshalObject encodes an object to binary format
|
||||
func MarshalObject(object interface{}) ([]byte, error) {
|
||||
// Special case for the VERSION bucket. Here we're not using json
|
||||
if v, ok := object.(string); ok {
|
||||
return []byte(v), nil
|
||||
}
|
||||
|
||||
return json.Marshal(object)
|
||||
}
|
||||
|
||||
// UnmarshalObject decodes an object from binary data
|
||||
func UnmarshalObject(data []byte, object interface{}) error {
|
||||
return json.Unmarshal(data, object)
|
||||
// Special case for the VERSION bucket. Here we're not using json
|
||||
// So we need to return it as a string
|
||||
err := json.Unmarshal(data, object)
|
||||
if err != nil {
|
||||
if s, ok := object.(*string); ok {
|
||||
*s = string(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalObjectWithJsoniter decodes an object from binary data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue