Proper context.Context usage

This commit is contained in:
Caleb Gardner
2024-10-24 00:00:08 -05:00
parent fcab9458ee
commit 6965917e76
19 changed files with 126 additions and 118 deletions
+2 -3
View File
@@ -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