package main import ( "log" ) func (app *App) insertShops() error { shops := getShopsFromStruct() query := `INSERT IGNORE INTO shop (name, url, logo_url, shipping_costs, free_shipping) VALUES(?, ?, ?, ?, ?)` for _, v := range shops { _, err := app.DB.Exec(query, v.Name, v.Url, v.Logo_url, v.Shipping_costs, v.Free_shipping) if err != nil { return err } } return nil } func getShopsFromStruct() []Shop { Shops := []Shop{} Shops = append(Shops, Shop{ Name: "Bottleworld", Url: "https://www.bottleword.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "MC Whisky", Url: "https://www.mcwhisky.com", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Rum & Co", Url: "https://www.rumundco.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Whic", Url: "https://whic.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Whisky.de", Url: "https://www.whisky.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Whiskysite.nl", Url: "https://www.whiskysite.nl", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Whisky World", Url: "https://www.whiskyworld.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) Shops = append(Shops, Shop{ Name: "Whiskyzone", Url: "https://www.whiskyzone.de", Logo_url: "", Shipping_costs: 0, Free_shipping: "", }) return Shops } func (app *App) getShops() ([]Shop, error) { Shops := []Shop{} query := `SELECT id,name,url,logo_url,shipping_costs,free_shipping FROM shop` rows, err := app.DB.Queryx(query) if err != nil { return []Shop{}, err } defer rows.Close() for rows.Next() { var shop Shop err = rows.StructScan(&shop) if err != nil { return []Shop{}, err } if app.Config.Debug { log.Println("Appending: " + shop.Name) } Shops = append(Shops, shop) } return Shops, nil }