34 lines
668 B
Go
34 lines
668 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type Task struct {
|
|
URIPath string `json:"url,omitempty" :"url"`
|
|
Methode string `json:"method,omitempty" :"method"`
|
|
Channel chan any `:"channel"`
|
|
}
|
|
|
|
type Queue struct {
|
|
elements []Task
|
|
}
|
|
|
|
func (queue *Queue) Pop() (Task, error) {
|
|
if len(queue.elements) == 0 {
|
|
return Task{}, errors.New("try to remove an element of a empty queue")
|
|
}
|
|
task := queue.elements[0]
|
|
queue.elements = queue.elements[1:]
|
|
return task, nil
|
|
}
|
|
|
|
func (queue *Queue) Push(task Task) error {
|
|
empty := Task{}
|
|
if task == empty {
|
|
return errors.New("try to add task but task is empty")
|
|
}
|
|
queue.elements = append(queue.elements, task)
|
|
return nil
|
|
}
|