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 894 B

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