Use %q to quote a string in fmt.Sprintf format specifiers GO-R4002
Anti-pattern
Minor
8 months agoa year old
use %q instead of "%s" for quoted strings
34
35// MarshalJSON returns the duration as a JSON string.
36func (d *Duration) MarshalJSON() ([]byte, error) {
37	return []byte(fmt.Sprintf(`"%s"`, d.String())), nil38}
39
40// UnmarshalJSON parses a JSON string into the duration.