MCPcopy Create free account
hub / github.com/beeker1121/goque / Push

Method Push

stack.go:58–83  ·  view source on GitHub ↗

Push adds an item to the stack.

(value []byte)

Source from the content-addressed store, hash-verified

56
57// Push adds an item to the stack.
58func (s *Stack) Push(value []byte) (*Item, error) {
59 s.Lock()
60 defer s.Unlock()
61
62 // Check if stack is closed.
63 if !s.isOpen {
64 return nil, ErrDBClosed
65 }
66
67 // Create new Item.
68 item := &Item{
69 ID: s.head + 1,
70 Key: idToKey(s.head + 1),
71 Value: value,
72 }
73
74 // Add it to the stack.
75 if err := s.db.Put(item.Key, item.Value, nil); err != nil {
76 return nil, err
77 }
78
79 // Increment head position.
80 s.head++
81
82 return item, nil
83}
84
85// PushString is a helper function for Push that accepts a
86// value as a string rather than a byte slice.

Callers 4

PushStringMethod · 0.95
PushObjectMethod · 0.95
PushObjectAsJSONMethod · 0.95
Example_stackFunction · 0.80

Calls 1

idToKeyFunction · 0.85

Tested by 1

Example_stackFunction · 0.64