interfaceToBytes converts an interface to a byte slice
(value interface{})
| 30 | |
| 31 | // interfaceToBytes converts an interface to a byte slice |
| 32 | func interfaceToBytes(value interface{}) ([]byte, error, string) { |
| 33 | switch value := value.(type) { |
| 34 | |
| 35 | case string: |
| 36 | return []byte(value), nil, "string" |
| 37 | case int: |
| 38 | return []byte(strconv.Itoa(value)), nil, "int" |
| 39 | case int64: |
| 40 | return []byte(strconv.FormatInt(value, 10)), nil, "int64" |
| 41 | case float64: |
| 42 | return []byte(strconv.FormatFloat(value, 'f', -1, 64)), nil, "float64" |
| 43 | case bool: |
| 44 | return []byte(strconv.FormatBool(value)), nil, "bool" |
| 45 | case []byte: |
| 46 | return value, nil, "[]byte" |
| 47 | default: |
| 48 | return nil, errors.New("unsupported type"), "" |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func interfaceToString(value interface{}) (string, error) { |
| 53 | switch value := value.(type) { |