github.com/argoproj/argo-events@v1.9.1/pkg/apis/common/amount.go (about) 1 package common 2 3 import "strconv" 4 5 /** 6 This inspired by intstr.IntOrStr and json.Number. 7 */ 8 9 // Amount represent a numeric amount. 10 type Amount struct { 11 Value []byte `json:"value" protobuf:"bytes,1,opt,name=value"` 12 } 13 14 func NewAmount(s string) Amount { 15 return Amount{Value: []byte(s)} 16 } 17 18 func (a *Amount) UnmarshalJSON(value []byte) error { 19 a.Value = value 20 return nil 21 } 22 23 func (n Amount) MarshalJSON() ([]byte, error) { 24 return n.Value, nil 25 } 26 27 func (n Amount) OpenAPISchemaType() []string { 28 return []string{"number"} 29 } 30 31 func (n Amount) OpenAPISchemaFormat() string { return "" } 32 33 func (n *Amount) Float64() (float64, error) { 34 return strconv.ParseFloat(string(n.Value), 64) 35 }