Proper context.Context usage
This commit is contained in:
@@ -49,9 +49,9 @@ func (b *CDRBackend) AddBackend(back *backend.Backend) {
|
||||
b.back = back
|
||||
}
|
||||
|
||||
func (s CDRBackend) AddCrash(cr backend.IndividualCrash) bool {
|
||||
res := s.db.Collection("versions").FindOne(context.Background(), bson.M{"version": cr.Version})
|
||||
return res.Err() != mongo.ErrNoDocuments
|
||||
func (s CDRBackend) ShouldAddCrash(ctx context.Context, cr backend.IndividualCrash) bool {
|
||||
res := s.db.Collection("versions").FindOne(ctx, bson.M{"version": cr.Version})
|
||||
return res.Err() == nil
|
||||
}
|
||||
|
||||
func (b CDRBackend) Extension(mux *http.ServeMux) {
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package cdr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
@@ -56,7 +55,7 @@ func (b CDRBackend) UploadDie(w http.ResponseWriter, r *http.Request) {
|
||||
if toUpload.Die["uuid"] != nil {
|
||||
delete(toUpload.Die, "uuid")
|
||||
}
|
||||
_, err = b.db.Collection("dice").InsertOne(context.Background(), toUpload)
|
||||
_, err = b.db.Collection("dice").InsertOne(r.Context(), toUpload)
|
||||
if err != nil {
|
||||
backend.ReturnError(w, http.StatusInternalServerError, "internal", "Server error")
|
||||
log.Println("error inserting die:", err)
|
||||
@@ -67,7 +66,7 @@ func (b CDRBackend) UploadDie(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (b CDRBackend) GetDie(w http.ResponseWriter, r *http.Request) {
|
||||
res := b.db.Collection("dice").FindOne(context.Background(), bson.M{"_id": r.PathValue("dieID")})
|
||||
res := b.db.Collection("dice").FindOne(r.Context(), bson.M{"_id": r.PathValue("dieID")})
|
||||
if res.Err() == mongo.ErrNoDocuments {
|
||||
backend.ReturnError(w, 404, "not found", "Die with the given id is not found")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user