Golang returns only "id"

Hi, i have an issue. I am learning go and trying to create a hostel API. But each time I use postman , I keep getting only the id value the rest don’t come out. I will like to know the error I am making Here is a screenshot of my problem

Can we see the code that responds to that API request?

Go doesn’t use keywords like public and private to distinguish accessibility of identifiers (fields, functions, types, etc); uppercase names are public and lowercase are private. The issue is your fields all start with lowercase names, so the json package cannot see any of them except for the ID field. Rename your fields so they start with uppercase letters.

4 Likes

thank you so very much

hi, Do you have any idea why this does not return a list of all students?

I get Error: read ECONNRESET on Postman?

image

Did you ask for students?

You log.Fatal(err) unconditionally. And assuming you use the go standard libraries log package, this means exiting your program unconditionally.

The table name is rooms
.

This is my log error
hh

In your screenshot, you’re calling log.Fatal(err), not your logFatal function. log.Fatal will abort the goroutine when it’s called so your rows are never scanned.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.