EnqueueObject is a helper function for Enqueue that accepts any value type, which is then encoded into a byte slice using encoding/gob. Objects containing pointers with zero values will decode to nil when using this function. This is due to how the encoding/gob package works. Because of this, you s
(value interface{})
| 97 | // package works. Because of this, you should only use this function |
| 98 | // to encode simple types. |
| 99 | func (q *Queue) EnqueueObject(value interface{}) (*Item, error) { |
| 100 | var buffer bytes.Buffer |
| 101 | enc := gob.NewEncoder(&buffer) |
| 102 | if err := enc.Encode(value); err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | |
| 106 | return q.Enqueue(buffer.Bytes()) |
| 107 | } |
| 108 | |
| 109 | // EnqueueObjectAsJSON is a helper function for Enqueue that accepts |
| 110 | // any value type, which is then encoded into a JSON byte slice using |