K
You have a few comments and mistakes in your code. First, initials don't match. https://github.com/golang/go/wiki/CodeReviewComments#initialisms ♪ Id must be ID♪Second, you have Russian and English characters in your code, for example, Сomposition Head С - Russian.Thirdly, you're trying to download what is defined in SQL code as a set of structures into one structure.Four, the Driver can't masturbate the postgras structures directly into the genes, so it needs to satisfy the interface. https://golang.org/pkg/database/sql/#Scanner ♪ Here's an example for one. Composition:func (c *Composition) Scan(src interface{}) error {
log.Println(string(src.([]byte)))
s := string(src.([]byte))
// Убираем скобки.
s = s[1 : len(s)-1]
// Разделяем.
parts := strings.Split(s, ",")
// Парсим части.
var err error
c.ID, err = strconv.Atoi(parts[0])
if err != nil {
return err
}
c.Name = parts[1]
c.Count, err = strconv.Atoi(parts[2])
if err != nil {
return err
}
c.Price, err = strconv.ParseFloat(parts[3], 64)
if err != nil {
return err
}
return nil
}
If you still want to download the mass, you'll feel better asking. to_json("Composition"), and in go, define the type Compositionswho can read himself from the OBD through JSON:type Compositions []Composition
func (c *Compositions) Scan(src interface{}) error {
b := src.([]byte)
err := json.Unmarshal(b, c)
if err != nil {
return err
}
return nil
}