MakeID coerces the given Go value to an ID. The value should be the default JSON marshaling of a Request identifier: nil, float64, or string. Returns an error if the value type was not a valid Request ID type. TODO: ID can't be a json.Marshaler/Unmarshaler, because we want to omitzero. Simplify th
(v any)
| 28 | // Simplify this package by making ID json serializable once we can rely on |
| 29 | // omitzero. |
| 30 | func MakeID(v any) (ID, error) { |
| 31 | switch v := v.(type) { |
| 32 | case nil: |
| 33 | return ID{}, nil |
| 34 | case float64: |
| 35 | return Int64ID(int64(v)), nil |
| 36 | case string: |
| 37 | return StringID(v), nil |
| 38 | } |
| 39 | return ID{}, fmt.Errorf("%w: invalid ID type %T", ErrParse, v) |
| 40 | } |
| 41 | |
| 42 | // Message is the interface to all jsonrpc2 message types. |
| 43 | // They share no common functionality, but are a closed set of concrete types |
no test coverage detected
searching dependent graphs…