Skip to content

Commit

Permalink
Merge pull request #1 from sotchenkov/fix/queue-handler
Browse files Browse the repository at this point in the history
queue handlers fixing - PUT requests were processed as GET
  • Loading branch information
sotchenkov authored Mar 21, 2024
2 parents f5cf38c + 446658a commit 7a5cf30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Limero is now ready to use ✨
## 🌀 Quick start
First, create a queue:
```shell
curl -LX PUT "http://127.0.0.1:7920/queue?name=helloworld"
curl -X PUT "http://127.0.0.1:7920/queue?name=helloworld"

{
"ok": true,
Expand All @@ -53,14 +53,14 @@ curl --request POST \
And now we will receive a message from the queue:
```shell
curl -LX GET "http://127.0.0.1:7920/msg?qname=helloworld"
curl -X GET "http://127.0.0.1:7920/msg?qname=helloworld"

{"value":"this is a new message!"}⏎
```
## 📃 Docs
To view all the documentation, open the address under the "docs" key in the browser:
```shell
curl -LX GET "http://127.0.0.1:7920/"
curl -X GET "http://127.0.0.1:7920/"

{
"limero": "Welcome!",
Expand All @@ -78,7 +78,7 @@ By opening the url in the browser, you can view the full swagger documentation
## 🌟 Tips
You can allocate the queue size in advance if you know the average number of messages that will be in the queue. This will increase the queue performance ⚡
```shell
curl -LX PUT "http://127.0.0.1:7920/queue?name=helloworld&size=100"
curl -X PUT "http://127.0.0.1:7920/queue?name=helloworld&size=100"

{
"ok": true,
Expand Down
12 changes: 9 additions & 3 deletions internal/server/handlers/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ import (

var queues = make(map[string]*queue.Queue)

func Queue(w http.ResponseWriter, r *http.Request) {
func ActionOnQueueHandlers(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPut:
createQueue(w, r)
case http.MethodDelete:
deleteQueue(w, r)
case http.MethodGet:
default:
response.Send(w, http.StatusMethodNotAllowed, response.Error{Error: "method_not_allowed", Info: "Only PUT, DELETE methods"})
}
}

func InfoAboutQueueHandlers(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
if len(r.URL.Path[len("/queue/"):]) > 0 {
queueInfo(w, r)
} else {
Queues(w, r)
}
default:
} else {
response.Send(w, http.StatusMethodNotAllowed, response.Error{Error: "method_not_allowed", Info: "Only PUT, DELETE methods"})
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func Serv(zlog *zap.Logger) {

mux.HandleFunc("/", handlers.Root)
mux.HandleFunc("/ping", handlers.Ping)
mux.HandleFunc("/queue/", handlers.Queue)
mux.HandleFunc("/queue", handlers.ActionOnQueueHandlers)
mux.HandleFunc("/queue/", handlers.InfoAboutQueueHandlers)
mux.HandleFunc("/msg", handlers.Msg)

loggedMux := logger.LoggerMiddleware(zlog)(mux)
Expand Down

0 comments on commit 7a5cf30

Please sign in to comment.