scalarString renders a JSON scalar as text. JSON numbers decode to float64; whole numbers are rendered without a trailing ".0" so a code of 400 prints as "400". Returns "" for nil and empty strings.
(v any)
| 762 | // whole numbers are rendered without a trailing ".0" so a code of 400 prints |
| 763 | // as "400". Returns "" for nil and empty strings. |
| 764 | func scalarString(v any) string { |
| 765 | switch x := v.(type) { |
| 766 | case nil: |
| 767 | return "" |
| 768 | case string: |
| 769 | return x |
| 770 | case float64: |
| 771 | if x == float64(int64(x)) { |
| 772 | return strconv.FormatInt(int64(x), 10) |
| 773 | } |
| 774 | return strconv.FormatFloat(x, 'g', -1, 64) |
| 775 | default: |
| 776 | return fmt.Sprint(v) |
| 777 | } |
| 778 | } |
no outgoing calls