40 lines
786 B
Go
40 lines
786 B
Go
package types
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type SupportedCurrency string
|
|
|
|
func (s *SupportedCurrency) UnmarshalJSON(bytes []byte) error {
|
|
var str string
|
|
if err := json.Unmarshal(bytes, &str); err != nil {
|
|
return err
|
|
}
|
|
switch str {
|
|
case "WEI":
|
|
*s = SupportedCurrencyWEI
|
|
case "EUR":
|
|
*s = SupportedCurrencyEUR
|
|
case "USD":
|
|
*s = SupportedCurrencyUSD
|
|
case "GBP":
|
|
*s = SupportedCurrencyGBP
|
|
default:
|
|
return fmt.Errorf("unsupported currency: %s", str)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s SupportedCurrency) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(string(s))
|
|
}
|
|
|
|
const (
|
|
SupportedCurrencyWEI SupportedCurrency = "WEI"
|
|
SupportedCurrencyEUR SupportedCurrency = "EUR"
|
|
SupportedCurrencyUSD SupportedCurrency = "USD"
|
|
SupportedCurrencyGBP SupportedCurrency = "GBP"
|
|
)
|