Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -6,18 +6,21 @@ import ( |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 | 8 |
const ( |
| 9 |
- // Define our own version of RFC339Nano because we want one |
|
| 9 |
+ // RFC3339NanoFixed is our own version of RFC339Nano because we want one |
|
| 10 | 10 |
// that pads the nano seconds part with zeros to ensure |
| 11 | 11 |
// the timestamps are aligned in the logs. |
| 12 | 12 |
RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00" |
| 13 |
- JSONFormat = `"` + time.RFC3339Nano + `"` |
|
| 13 |
+ // JSONFormat is the format used by FastMarshalJSON |
|
| 14 |
+ JSONFormat = `"` + time.RFC3339Nano + `"` |
|
| 14 | 15 |
) |
| 15 | 16 |
|
| 17 |
+// FastMarshalJSON avoids one of the extra allocations that |
|
| 18 |
+// time.MarshalJSON is making. |
|
| 16 | 19 |
func FastMarshalJSON(t time.Time) (string, error) {
|
| 17 | 20 |
if y := t.Year(); y < 0 || y >= 10000 {
|
| 18 | 21 |
// RFC 3339 is clear that years are 4 digits exactly. |
| 19 | 22 |
// See golang.org/issue/4556#c15 for more discussion. |
| 20 |
- return "", errors.New("Time.MarshalJSON: year outside of range [0,9999]")
|
|
| 23 |
+ return "", errors.New("time.MarshalJSON: year outside of range [0,9999]")
|
|
| 21 | 24 |
} |
| 22 | 25 |
return t.Format(JSONFormat), nil |
| 23 | 26 |
} |