2018-10-25 18:06:54 +02:00
|
|
|
package initializers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
. "Elektromarket/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initializePages() {
|
|
|
|
Pages = make(map[string]Page)
|
2018-10-26 10:40:11 +02:00
|
|
|
Pages["index"] = Page{"/", "templates/index.html", map[string]interface{}{"categories": Categories}, nil}
|
|
|
|
Pages["category"] = Page{"/category", "templates/category.html", map[string]interface{}{}, DynamicDataLoaderCategory}
|
2018-10-26 17:53:00 +02:00
|
|
|
Pages["product"] = Page{"/product", "templates/product.html", map[string]interface{}{}, DynamicDataLoaderProduct}
|
2018-10-25 18:06:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func initializeData() {
|
|
|
|
Categories = []Category {
|
|
|
|
{1, "Laptopy"},
|
|
|
|
{2, "Komputery"},
|
|
|
|
{3, "Smartfony"},
|
2018-10-26 17:53:00 +02:00
|
|
|
{4, "Smartwatche"},
|
2018-10-25 18:06:54 +02:00
|
|
|
{5, "Monitory"},
|
|
|
|
{6, "Drukarki"},
|
|
|
|
{7, "Myszki"},
|
|
|
|
{8, "Klawiatury"},
|
|
|
|
{9, "Akcesoria"},
|
|
|
|
}
|
2018-10-25 20:09:08 +02:00
|
|
|
|
|
|
|
Products = []Product {
|
|
|
|
{
|
|
|
|
1,
|
|
|
|
GetCategoryByName("Laptopy"),
|
|
|
|
"Apple MacBook Air 128 GB",
|
2018-10-26 17:53:00 +02:00
|
|
|
"Procesor Intel Core i5 | Pamięć 8 GB | Dysk SSD M.2 PCIe 128 GB | Grafika Intel HD Graphics 6000 | Typ ekranu Błyszczący, LED | System macOS Sierra",
|
2018-10-25 20:09:08 +02:00
|
|
|
"https://cdn.x-kom.pl/i/setup/images/prod/big/product-big,apple-macbook-air-i58gb128gbhd-6000mac-os-368639,pr_2016_4_28_12_39_54_140.jpg",
|
|
|
|
11,
|
|
|
|
3999,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
2,
|
2018-10-26 17:53:00 +02:00
|
|
|
GetCategoryByName("Laptopy"),
|
|
|
|
"Dell Inspiron 5370",
|
|
|
|
"Procesor Intel Core i5-8250U | Pamięć 8 GB | Dysk SSD M.2 256 GB | Grafika AMD Radeon 530, + Intel UHD Graphics 620 | Typ ekranu Matowy, LED | System Microsoft Windows 10 Home PL",
|
|
|
|
"https://cdn.x-kom.pl/i/setup/images/prod/big/product-big,dell-inspiron-5370-i5-8250u8gb256win10-r530-fhd-393456,2017/12/pr_2017_12_14_9_40_43_405_10.jpg",
|
|
|
|
5,
|
|
|
|
3249,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
3,
|
2018-10-25 20:09:08 +02:00
|
|
|
GetCategoryByName("Komputery"),
|
|
|
|
"Dell Inspiron 3670",
|
2018-10-26 17:53:00 +02:00
|
|
|
"System Microsoft Windows 10 Home PL | Procesor Intel Core i7-8700 | Grafika NVIDIA GeForce GTX 1050Ti, + Intel UHD Graphics 630 | Pamięć RAM 8 GB | Dysk SSD PCIe 128 GB | Dysk HDD SATA 7200 obr. 1000 GB | Miejsce na dodatkowy wewnętrzny dysk SATA Możliwość montażu dwóch dysków SATA",
|
2018-10-25 20:09:08 +02:00
|
|
|
"https://cdn.x-kom.pl/i/setup/images/prod/big/product-big,dell-inspiron-3670-i7-87008gb1281000win10-gtx1050ti-447395,2018/9/pr_2018_9_20_15_45_5_770_00.jpg",
|
|
|
|
123,
|
|
|
|
4299,
|
|
|
|
},
|
|
|
|
}
|
2018-10-25 18:06:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Initialize() {
|
|
|
|
initializeData()
|
2018-10-25 20:09:08 +02:00
|
|
|
initializePages()
|
2018-10-25 18:06:54 +02:00
|
|
|
for k := range Pages {
|
|
|
|
http.HandleFunc(Pages[k].Path, Pages[k].HandlePage)
|
|
|
|
}
|
2018-10-25 20:31:50 +02:00
|
|
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
2018-10-25 18:06:54 +02:00
|
|
|
http.ListenAndServe(":8000", nil)
|
|
|
|
}
|