lib/model: Make /browse endpoint return sane objects (#7306)

This commit is contained in:
Audrius Butkevicius
2021-02-01 09:27:34 +01:00
committed by GitHub
parent 052dc13487
commit a7d9268e4d
5 changed files with 219 additions and 297 deletions
+18
View File
@@ -5,6 +5,7 @@ package protocol
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"runtime"
@@ -394,3 +395,20 @@ func VectorHash(v Vector) []byte {
}
return h.Sum(nil)
}
func (x *FileInfoType) MarshalJSON() ([]byte, error) {
return json.Marshal(x.String())
}
func (x *FileInfoType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
n, ok := FileInfoType_value[s]
if !ok {
return errors.New("invalid value: " + s)
}
*x = FileInfoType(n)
return nil
}