PushObjectAsJSON is a helper function for Push 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.
(value interface{})
| 112 | // |
| 113 | // Use this function to handle encoding of complex types. |
| 114 | func (s *Stack) PushObjectAsJSON(value interface{}) (*Item, error) { |
| 115 | jsonBytes, err := json.Marshal(value) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | |
| 120 | return s.Push(jsonBytes) |
| 121 | } |
| 122 | |
| 123 | // Pop removes the next item in the stack and returns it. |
| 124 | func (s *Stack) Pop() (*Item, error) { |