appendValue appends a value to the buffer, applying quoting rules as necessary.
(val slog.Value)
| 141 | |
| 142 | // appendValue appends a value to the buffer, applying quoting rules as necessary. |
| 143 | func (s *formatterJSON) appendValue(val slog.Value) { |
| 144 | switch val.Kind() { |
| 145 | case slog.KindString: |
| 146 | s.appendString(val.String()) |
| 147 | case slog.KindInt64: |
| 148 | s.buf.appendInt(val.Int64()) |
| 149 | case slog.KindUint64: |
| 150 | s.buf.appendUint(val.Uint64()) |
| 151 | case slog.KindFloat64: |
| 152 | // strconv.FormatFloat result sometimes differs from json.Marshal, |
| 153 | // so we use json.Marshal for consistency. |
| 154 | s.appendJSONMarshal(val.Float64()) |
| 155 | case slog.KindBool: |
| 156 | s.buf.appendBool(val.Bool()) |
| 157 | case slog.KindDuration: |
| 158 | s.buf.appendInt(int64(val.Duration())) |
| 159 | case slog.KindTime: |
| 160 | s.appendTime(val.Time()) |
| 161 | default: |
| 162 | s.appendJSONMarshal(val.Any()) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // appendString appends a string value to the buffer. |
| 167 | // If the string does not require escaping, it is appended directly. |
no test coverage detected