UpdateObjectAsJSON is a helper function for Update that accepts any value type, which is then encoded into a JSON byte slice using encoding/json. Use this function to handle encoding of complex types.
(id uint64, newValue interface{})
| 246 | // |
| 247 | // Use this function to handle encoding of complex types. |
| 248 | func (s *Stack) UpdateObjectAsJSON(id uint64, newValue interface{}) (*Item, error) { |
| 249 | jsonBytes, err := json.Marshal(newValue) |
| 250 | if err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | |
| 254 | return s.Update(id, jsonBytes) |
| 255 | } |
| 256 | |
| 257 | // Length returns the total number of items in the stack. |
| 258 | func (s *Stack) Length() uint64 { |