The backend for the project formerly known as signet, now known as beignet.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

createqueue.go 778 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. . "github.com/imosed/signet/data"
  6. )
  7. type CreateQueueRequest struct {
  8. Name string `json:"name"`
  9. }
  10. type CreateQueueResponse struct {
  11. ID uint `json:"id"`
  12. }
  13. func CreateQueue(w http.ResponseWriter, r *http.Request) {
  14. var req CreateQueueRequest
  15. err := json.NewDecoder(r.Body).Decode(&req)
  16. if err != nil {
  17. panic("Could not decode body")
  18. }
  19. var specificQueue Queue
  20. Db.Table("queues").First(&specificQueue, "name = ?", req.Name)
  21. var resp CreateQueueResponse
  22. if specificQueue.ID != 0 {
  23. resp.ID = specificQueue.ID
  24. } else {
  25. queue := Queue{
  26. Name: req.Name,
  27. }
  28. Db.Create(&queue)
  29. resp.ID = queue.ID
  30. }
  31. err = json.NewEncoder(w).Encode(resp)
  32. if err != nil {
  33. panic("Could not deliver response")
  34. }
  35. }