carpool-service/interoperability/ocss/prices.go

51 lines
963 B
Go
Raw Normal View History

2023-03-27 18:54:56 +00:00
package ocss
2023-03-30 06:44:58 +00:00
import (
"bytes"
"encoding/json"
)
2023-03-27 18:54:56 +00:00
type PriceType int64
const (
Free PriceType = iota
Paying
Unknown
)
2023-03-30 06:44:58 +00:00
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
}
2023-03-27 18:54:56 +00:00
type Price struct {
Type *PriceType `json:"type,omitempty"`
Amount *float64 `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
}