You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have a mistake in your struct tags, go test will show you the problem.
Thank you for raising this issue. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm making an HTTP request to the go backend server which fetches the record from mongodb atlas database.
Database contains just one record:
GetProfile returns UserProfile user
func GetProfile(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Methods", "GET")
params := mux.Vars(r)
var user models.UserProfile
fmt.Println("getProfile for : ", params["uid"])
filter := bson.M{"uid": params["uid"]}
err := collection.FindOne(context.Background(), filter).Decode(&user)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(
{ "message": "
+ err.Error() +" }
))return
// user = createUser(params["uid"])
}
json.NewEncoder(w).Encode(user)
}
router snippet
router := mux.NewRouter()
router.HandleFunc("/api/userProfile/{uid}", middleware.GetProfile).Methods("GET", "OPTIONS")
data-struct
type UserProfile struct {
ID primitive.ObjectID
json:"_id" bson:"_id"
UserID string
json:"uid" bson:"uid"
Pantry []string
json:"pantry" bson:"pantry"
Cart []string
json:"cart" bson:"cart"
Favourites []string
json:"fav" bson:"fav"
}
What did you expect to see?
url in postman: http://localhost:8080/api/userProfile/aditit@andrew.cmu.edu
What did you see instead?
The text was updated successfully, but these errors were encountered: