Skip to content

Commit

Permalink
WATCHER: (WIP) Add queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Cian911 committed Jan 6, 2022
1 parent 59ea81c commit 5050fea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions watcher/queue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package watcher

import (
"crypto/md5"
"fmt"

"github.com/cian911/switchboard/event"
)

type Queue struct {
queue map[string]event.Event
}

func New() *Queue {
return &Queue{
queue: make(map[string]event.Event),
}
}

func (q *Queue) Add(hash string, ev event.Event) {
q.queue[hash] = ev
}

func (q *Queue) Retrieve(hash string) event.Event {
return q.queue[hash]
}

func (q *Queue) Remove(hash string) {
delete(q.queue, hash)
}

func generateHash(ev event.Event) string {
data := []byte(fmt.Sprintf("%s%s%s%s", ev.File, ev.Path, ev.Destination, ev.Ext))
return fmt.Sprintf("%x", md5.Sum(data))
}
Empty file added watcher/queue_test.go
Empty file.

0 comments on commit 5050fea

Please sign in to comment.