mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-16 08:55:31 +01:00
refactored gametime and utils folder which decouples entrance and sign from channel servers
This commit is contained in:
38
utils/stringstack/stringstack.go
Normal file
38
utils/stringstack/stringstack.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package stringstack
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// StringStack is a basic LIFO "stack" for storing strings.
|
||||
type StringStack struct {
|
||||
stack []string
|
||||
}
|
||||
|
||||
// New creates a new instance of StringStack
|
||||
func New() *StringStack {
|
||||
return &StringStack{}
|
||||
}
|
||||
|
||||
// Set sets up a new StringStack
|
||||
func (s *StringStack) Set(v string) {
|
||||
s.stack = []string{v}
|
||||
}
|
||||
|
||||
// Push pushes a string onto the stack.
|
||||
func (s *StringStack) Push(v string) {
|
||||
s.stack = append(s.stack, v)
|
||||
}
|
||||
|
||||
// Pop pops a string from the stack.
|
||||
func (s *StringStack) Pop() (string, error) {
|
||||
var x string
|
||||
if len(s.stack) == 0 {
|
||||
return x, errors.New("no items on stack")
|
||||
}
|
||||
|
||||
x = s.stack[len(s.stack)-1]
|
||||
s.stack = s.stack[:len(s.stack)-1]
|
||||
|
||||
return x, nil
|
||||
}
|
||||
Reference in New Issue
Block a user