1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
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
}
|