UnmarshalJSON lets a struct field typed as Untrusted be populated directly by json.Unmarshal, so provenance is preserved across a JSON decode. This is what lets a decoded field (e.g. a streamed log line) stay labeled when the surrounding response was never sanitized by the JSON transport.
(data []byte)
| 61 | // lets a decoded field (e.g. a streamed log line) stay labeled when |
| 62 | // the surrounding response was never sanitized by the JSON transport. |
| 63 | func (u *Untrusted) UnmarshalJSON(data []byte) error { |
| 64 | var s string |
| 65 | if err := json.Unmarshal(data, &s); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | u.raw = s |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | // MarshalJSON emits the raw content as a JSON string so a value round-trips |
| 73 | // faithfully through encode/decode. |
no outgoing calls
no test coverage detected