4 ms·
Gah, Go pet peave, they could just use a map literal (good for short low-perf code). Or even better perf/safety wise: type Payload struct { Name string
by voidlogic 11y ago
Gah, Go pet peave, they could just use a map literal (good for short low-perf code).
Or even better perf/safety wise:
type Payload struct {
Name string `json:"name"`
Category string `json:"category"`
Action string `json:"action"`
Where string `json:"where"`
Timestamp int64 `json:"timestamp,string"`
}
payload := Payload{
Name: "joe smith",
Category: "people",
Action: "transport"
Where: "pluto",
Timestamp: time.Now().Unix(),
}
jsonBytes, err := json.Marshal(&payload)
This code doesn't allocate heap for payload, is much faster and typesafe...
P.S. And could be shorter, but I was trying to be clear.