package endpoints import ( "encoding/json" "net/http" . "github.com/imosed/signet/data" ) type CreateQueueRequest struct { Name string `json:"name"` } type CreateQueueResponse struct { ID uint `json:"id"` } func CreateQueue(w http.ResponseWriter, r *http.Request) { var req CreateQueueRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { panic("Could not decode body") } var specificQueue Queue Db.Table("queues").First(&specificQueue, "name = ?", req.Name) var resp CreateQueueResponse if specificQueue.ID != 0 { resp.ID = specificQueue.ID } else { queue := Queue{ Name: req.Name, } Db.Create(&queue) resp.ID = queue.ID } err = json.NewEncoder(w).Encode(resp) if err != nil { panic("Could not deliver response") } }