types: serialize pin types as string and not as a number

The pin type in json objects will not be understandable by humans
This commit is contained in:
Hector Sanjuan 2022-04-07 14:44:04 +02:00
parent a2b89f9b3b
commit f01612ca63

View File

@ -622,6 +622,23 @@ func (pT PinType) String() string {
}
}
// MarshalJSON provides json-representation of the pin type.
func (pT PinType) MarshalJSON() ([]byte, error) {
return json.Marshal(pT.String())
}
// UnmarshalJSON provides json-representation of the pin type.
func (pT *PinType) UnmarshalJSON(b []byte) error {
var str string
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
t := PinTypeFromString(str)
*pT = t
return nil
}
var pinOptionsMetaPrefix = "meta-"
// PinMode is a PinOption that indicates how to pin something on IPFS,