Proper context.Context usage
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package swassistant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
@@ -61,7 +60,7 @@ func (s *SWBackend) UploadProfile(w http.ResponseWriter, r *http.Request) {
|
||||
Type: profType,
|
||||
Profile: prof,
|
||||
}
|
||||
_, err = s.db.Collection("profiles").InsertOne(context.Background(), toUpload)
|
||||
_, err = s.db.Collection("profiles").InsertOne(r.Context(), toUpload)
|
||||
if err != nil {
|
||||
backend.ReturnError(w, http.StatusInternalServerError, "internal", "Server error")
|
||||
log.Println("error inserting profile:", err)
|
||||
@@ -72,7 +71,7 @@ func (s *SWBackend) UploadProfile(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *SWBackend) GetProfile(w http.ResponseWriter, r *http.Request) {
|
||||
res := s.db.Collection("profiles").FindOne(context.Background(), bson.M{"_id": r.PathValue("profileID")})
|
||||
res := s.db.Collection("profiles").FindOne(r.Context(), bson.M{"_id": r.PathValue("profileID")})
|
||||
if res.Err() == mongo.ErrNoDocuments {
|
||||
backend.ReturnError(w, 404, "not found", "Profile not found")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user