valueString returns the string representation of a value.
(v reflect.Value, opts tagOptions, sf reflect.StructField)
| 277 | |
| 278 | // valueString returns the string representation of a value. |
| 279 | func valueString(v reflect.Value, opts tagOptions, sf reflect.StructField) string { |
| 280 | for v.Kind() == reflect.Ptr { |
| 281 | if v.IsNil() { |
| 282 | return "" |
| 283 | } |
| 284 | v = v.Elem() |
| 285 | } |
| 286 | |
| 287 | if v.Kind() == reflect.Bool && opts.Contains("int") { |
| 288 | if v.Bool() { |
| 289 | return "1" |
| 290 | } |
| 291 | return "0" |
| 292 | } |
| 293 | |
| 294 | if v.Type() == timeType { |
| 295 | t := v.Interface().(time.Time) |
| 296 | if opts.Contains("unix") { |
| 297 | return strconv.FormatInt(t.Unix(), 10) |
| 298 | } |
| 299 | if opts.Contains("unixmilli") { |
| 300 | return strconv.FormatInt((t.UnixNano() / 1e6), 10) |
| 301 | } |
| 302 | if opts.Contains("unixnano") { |
| 303 | return strconv.FormatInt(t.UnixNano(), 10) |
| 304 | } |
| 305 | if layout := sf.Tag.Get("layout"); layout != "" { |
| 306 | return t.Format(layout) |
| 307 | } |
| 308 | return t.Format(time.RFC3339) |
| 309 | } |
| 310 | |
| 311 | return fmt.Sprint(v.Interface()) |
| 312 | } |
| 313 | |
| 314 | // isEmptyValue checks if a value should be considered empty for the purposes |
| 315 | // of omitting fields with the "omitempty" option. |
no test coverage detected
searching dependent graphs…