Merge pull request #1628 from ipfs/feat/pin-type-json

types: serialize pin types as string and not as a number
This commit is contained in:
Hector Sanjuan 2022-04-07 15:01:41 +02:00 committed by GitHub
commit 6706cb9e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,