package model import ( "errors" ) type RecipesElement struct { Id int64 Title string } type Recipes []RecipesElement func (r *Recipes) Read() error { if len(*r) != 0 { return errors.New("Recipes has to contain zero elements for .Read()") } query := `SELECT id, title FROM recipes` rows, err := db.Query(query) if err != nil { return err } defer rows.Close() for rows.Next() { element := RecipesElement{} err = rows.Scan(&element.Id, &element.Title) if err != nil { return err } *r = append(*r, element) } return nil }