This commit is contained in:
2023-03-30 08:44:58 +02:00
parent bf6453b963
commit 0ae5730e7f
17 changed files with 305 additions and 44 deletions

View File

@@ -1,5 +1,10 @@
package ocss
import (
"bytes"
"encoding/json"
)
type PriceType int64
const (
@@ -8,6 +13,36 @@ const (
Unknown
)
var priceTypeToID = map[string]PriceType{
"FREE": Free,
"PAYING": Paying,
"UNKNOWN": Unknown,
}
var priceTypeToString = map[PriceType]string{
Free: "FREE",
Paying: "PAYING",
Unknown: "UNKNOWN",
}
func (s PriceType) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(priceTypeToString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *PriceType) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*bs = priceTypeToID[j]
return nil
}
type Price struct {
Type *PriceType `json:"type,omitempty"`
Amount *float64 `json:"amount,omitempty"`