94 lines
1.7 KiB
Go
94 lines
1.7 KiB
Go
package param
|
|
|
|
import (
|
|
"encoding"
|
|
"strconv"
|
|
|
|
"ruben/inventory2/domains/accounts"
|
|
)
|
|
|
|
// encoding.TextUnmarshaler instances for Spec
|
|
|
|
func Text(dst *string) encoding.TextUnmarshaler {
|
|
return (*rawText)(dst)
|
|
}
|
|
|
|
func Int(dst *int) encoding.TextUnmarshaler {
|
|
return (*intText)(dst)
|
|
}
|
|
|
|
func Int64(dst *int64) encoding.TextUnmarshaler {
|
|
return (*int64Text)(dst)
|
|
}
|
|
|
|
func Float64(dst *float64) encoding.TextUnmarshaler {
|
|
return (*float64Text)(dst)
|
|
}
|
|
|
|
func Bool(dst *bool) encoding.TextUnmarshaler {
|
|
return (*boolText)(dst)
|
|
}
|
|
|
|
func Platform(dst *accounts.Platform) encoding.TextUnmarshaler {
|
|
return (*platformText)(dst)
|
|
}
|
|
|
|
type (
|
|
rawText string
|
|
intText int
|
|
int64Text int64
|
|
float64Text float64
|
|
boolText bool
|
|
platformText accounts.Platform
|
|
)
|
|
|
|
func (t *rawText) UnmarshalText(text []byte) error {
|
|
*t = rawText(text)
|
|
return nil
|
|
}
|
|
|
|
func (n *intText) UnmarshalText(text []byte) error {
|
|
i, err := strconv.Atoi(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*n = intText(i)
|
|
return nil
|
|
}
|
|
|
|
func (n *int64Text) UnmarshalText(text []byte) error {
|
|
i, err := strconv.ParseInt(string(text), 10, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*n = int64Text(i)
|
|
return nil
|
|
}
|
|
|
|
func (n *float64Text) UnmarshalText(text []byte) error {
|
|
i, err := strconv.ParseFloat(string(text), 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*n = float64Text(i)
|
|
return nil
|
|
}
|
|
|
|
func (b *boolText) UnmarshalText(text []byte) error {
|
|
v, err := strconv.ParseBool(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*b = boolText(v)
|
|
return nil
|
|
}
|
|
|
|
func (p *platformText) UnmarshalText(text []byte) error {
|
|
v, err := accounts.NewPlatform(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*p = platformText(v)
|
|
return nil
|
|
}
|