Structure of unstructured type s> 1 column

package main import ( "fmt" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" "net/http" "log" "encoding/json" "time" ) type serverStructV1 struct { id int `db:"id"` hostname string `db:"hostname"` nickname string `db:"nickname"` locationIp string `db:"location_ip"` updatedAt time.Time `db:"updatedAt"` } func serversHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, world/n") db, err := sqlx.Open("postgres", "postgres://afdata: afdata@ /afdata?sslmode=disable") if err!= nil{ log.Fatal(err) } defer db.Close() err = db.Ping() if err != nil { panic(err.Error()) } serversdisplay := []serverStructV1{} err = db.Select(&serversdisplay, "select id,hostname,nickname,location_ip,updatedAt from afdata.serversV1") if err != nil { log.Fatal(err) } } 

When I run it, it says struct struct struct struct struct s> 1 columns (5) if I change

  err = db.Select(&serversdisplay, "select id,hostname,nickname,location_ip,updatedAt from afdata.serversV1") 

in

  err = db.Select(&serversdisplay, "select id from afdata.serversV1") 

the result becomes zero. I am testing a select query using psql, it can return NOT NULL results. but even when the columns match, it returns null. It connects to the database, but does not receive the result of the request.

0
source share

All Articles