type Item interface{} // ItemStack the stack of Items type ItemStack struct { items []Item lock *sync.RWMutex } // New creates a new ItemStack func New(len int, cap int) *ItemStack { s := ItemStack{items: make([]Item, len, cap), lock: &sync.RWMutex{}} return &s } // Push adds an Item to the top of the stack func (s *ItemStack) Push(t Item) { s.lock.Lock() defer s.lock.Unlock() s.items = append(s.items, t) } // Pop removes an Item from the top of the stack func (s *ItemStack) Pop() *Item { s.lock.Lock() defer s.lock.Unlock() item := s.items[len(s.items)-1] s.items = s.items[0 : len(s.items)-1] return &item }