inline copy from globals.go of InterfaceMarshalFunc used in tests to avoid import cycle
(v interface{})
| 361 | |
| 362 | // inline copy from globals.go of InterfaceMarshalFunc used in tests to avoid import cycle |
| 363 | func InterfaceMarshalFunc(v interface{}) ([]byte, error) { |
| 364 | var buf bytes.Buffer |
| 365 | encoder := json.NewEncoder(&buf) |
| 366 | encoder.SetEscapeHTML(false) |
| 367 | err := encoder.Encode(v) |
| 368 | if err != nil { |
| 369 | return nil, err |
| 370 | } |
| 371 | b := buf.Bytes() |
| 372 | if len(b) > 0 { |
| 373 | // Remove trailing \n which is added by Encode. |
| 374 | return b[:len(b)-1], nil |
| 375 | } |
| 376 | return b, nil |
| 377 | } |