Files
tiennm99 cf620a257e docs: fix stale code comments and add missing package docs
Correct comments that described the retired webhook transport, a removed
/cron route, the old KV store and wrapper types, and behaviour that has since
changed; drop plan and review labels; reword two startup log lines that
overstated or misnamed what they report.
2026-09-30 14:19:01 +07:00

39 lines
1.2 KiB
Go

package coin
import "errors"
var errInvalidUSDAmount = errors.New("coin: invalid USD amount")
type coinValueArgs struct {
coin CoinSymbol
value float64
}
// parseCoinValueArgs accepts "<coin> <value>" or "<value> <coin>". When
// neither order parses, it returns ErrUnsupportedCoin if the second argument
// is a number (the coin was the bad part) and invalidValueErr otherwise.
func parseCoinValueArgs(args []string, validValue func(float64) bool, invalidValueErr error) (coinValueArgs, error) {
if len(args) != 2 {
return coinValueArgs{}, invalidValueErr
}
if coin, err := ResolveCoinSymbol(args[0]); err == nil {
value, ok := parsePositiveFinite(args[1])
if !ok || !validValue(value) {
return coinValueArgs{}, invalidValueErr
}
return coinValueArgs{coin: coin, value: value}, nil
}
value, ok := parsePositiveFinite(args[0])
if !ok || !validValue(value) {
if _, secondOK := parsePositiveFinite(args[1]); secondOK {
return coinValueArgs{}, ErrUnsupportedCoin
}
return coinValueArgs{}, invalidValueErr
}
coin, err := ResolveCoinSymbol(args[1])
if err != nil {
return coinValueArgs{}, err
}
return coinValueArgs{coin: coin, value: value}, nil
}