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

Function OpenStack

stack.go:25–55  ·  view source on GitHub ↗

OpenStack opens a stack if one exists at the given directory. If one does not already exist, a new stack is created.

(dataDir string)

Source from the content-addressed store, hash-verified

23// OpenStack opens a stack if one exists at the given directory. If one
24// does not already exist, a new stack is created.
25func OpenStack(dataDir string) (*Stack, error) {
26 var err error
27
28 // Create a new Stack.
29 s := &Stack{
30 DataDir: dataDir,
31 db: &leveldb.DB{},
32 head: 0,
33 tail: 0,
34 isOpen: false,
35 }
36
37 // Open database for the stack.
38 s.db, err = leveldb.OpenFile(dataDir, nil)
39 if err != nil {
40 return s, err
41 }
42
43 // Check if this Goque type can open the requested data directory.
44 ok, err := checkGoqueType(dataDir, goqueStack)
45 if err != nil {
46 return s, err
47 }
48 if !ok {
49 return s, ErrIncompatibleType
50 }
51
52 // Set isOpen and return.
53 s.isOpen = true
54 return s, s.init()
55}
56
57// Push adds an item to the stack.
58func (s *Stack) Push(value []byte) (*Item, error) {

Callers 15

Example_stackFunction · 0.92
TestStackCloseFunction · 0.85
TestStackDropFunction · 0.85
TestStackPushFunction · 0.85
TestStackPopFunction · 0.85
TestStackPeekFunction · 0.85
TestStackPeekByOffsetFunction · 0.85
TestStackPeekByIDFunction · 0.85
TestStackUpdateFunction · 0.85
TestStackUpdateStringFunction · 0.85

Calls 2

initMethod · 0.95
checkGoqueTypeFunction · 0.85

Tested by 15

Example_stackFunction · 0.74
TestStackCloseFunction · 0.68
TestStackDropFunction · 0.68
TestStackPushFunction · 0.68
TestStackPopFunction · 0.68
TestStackPeekFunction · 0.68
TestStackPeekByOffsetFunction · 0.68
TestStackPeekByIDFunction · 0.68
TestStackUpdateFunction · 0.68
TestStackUpdateStringFunction · 0.68