Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
zarnoevic committed Feb 28, 2024
1 parent f8c7287 commit 930d046
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ go.work
.DS_Store
.idea/
.env
a
a

*.json
*.js
node_modules/
8 changes: 4 additions & 4 deletions src/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func main() {
if err != nil {
log.Fatalf("Failed to consume messages: %s", err)
}
fmt.Printf("Consuming messages with msgs %v", msgs)
fmt.Printf("Consuming messages with msgs %v\n", msgs)

omap := orderedmap.NewOrderedMap()
fmt.Printf("Created ordered map %v", omap)
fmt.Printf("Created ordered map %v\n", omap)

processor := consumerService.NewConsumerService(omap)
fmt.Printf("Created consumer service %v", processor)
fmt.Printf("Created consumer service %v\n", processor)

for msg := range msgs {
fmt.Printf("Processing message %v", msg)
fmt.Printf("Processing message %v\n", msg)
processor.ProcessMessage(msg)
}
}
5 changes: 4 additions & 1 deletion src/pkg/services/consumerService/consumerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ func (cs *ConsumerService) ProcessMessage(d amqp091.Delivery) {
}

func (cs *ConsumerService) handleAdd(command []string) {
fmt.Printf("Add key: %s value: %s\n", command[1], command[2])
if len(command) != 3 {
log.Println("Add command requires 2 arguments: key and value")
return
}
cs.rwmu.Lock()
cs.omap.Add(command[1], command[2])
cs.rwmu.Unlock()
fmt.Println("Added key:", command[1], "value:", command[2])
}

func (cs *ConsumerService) handleGet(command []string) {
fmt.Printf("Get key: %s\n", command[1])
if len(command) != 2 {
log.Println("Get command requires 1 argument: key")
return
Expand All @@ -71,6 +72,7 @@ func (cs *ConsumerService) handleGet(command []string) {
}

func (cs *ConsumerService) handleDelete(command []string) {
fmt.Printf("Delete key: %s\n", command[1])
if len(command) != 2 {
fmt.Println("Delete command requires 1 argument: key")
return
Expand All @@ -81,6 +83,7 @@ func (cs *ConsumerService) handleDelete(command []string) {
}

func (cs *ConsumerService) handleGetAll() {
fmt.Println("Get all keys and values")
cs.rwmu.RLock()
allItems := cs.omap.GetAll()
cs.rwmu.RUnlock()
Expand Down

0 comments on commit 930d046

Please sign in to comment.