Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

type_float.go 677B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package config
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. type TypeFloat struct {
  7. value float64
  8. }
  9. func (c *TypeFloat) UnmarshalJSON(data []byte) error {
  10. value, err := strconv.ParseFloat(string(data), 64)
  11. if err != nil {
  12. return fmt.Errorf("incorrect float value: %w", err)
  13. }
  14. if value < 0 {
  15. return fmt.Errorf("%f should be positive", value)
  16. }
  17. c.value = value
  18. return nil
  19. }
  20. func (c *TypeFloat) MarshalText() ([]byte, error) {
  21. return []byte(c.String()), nil
  22. }
  23. func (c TypeFloat) String() string {
  24. return strconv.FormatFloat(c.value, 'f', -1, 64)
  25. }
  26. func (c TypeFloat) Value(defaultValue float64) float64 {
  27. if c.value < 0.00001 {
  28. return defaultValue
  29. }
  30. return c.value
  31. }