From bcef3ca10fe3666c135631170887cdda827e095f Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Sun, 18 Nov 2018 21:43:05 +0100 Subject: [PATCH 1/9] first commit --- redme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 redme.md diff --git a/redme.md b/redme.md new file mode 100644 index 0000000..e69de29 From 02a74fe9b22350cbce5d8767a11001315cb7cfd3 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Sun, 18 Nov 2018 21:52:49 +0100 Subject: [PATCH 2/9] second commit --- plik.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 plik.go diff --git a/plik.go b/plik.go new file mode 100644 index 0000000..da6df8a --- /dev/null +++ b/plik.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "net/http" + +) + +func hello(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "to dziala :)") +} + + +func main(){ + http.HandleFunc("/", hello) + http.ListenAndServe(":8080", nil) +} \ No newline at end of file From 8606fdf632ca74102e6b49b9331f8f94bf9cb7b2 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Wed, 21 Nov 2018 20:31:05 +0100 Subject: [PATCH 3/9] go --- gotut.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 gotut.go diff --git a/gotut.go b/gotut.go new file mode 100755 index 0000000..28527cb --- /dev/null +++ b/gotut.go @@ -0,0 +1,62 @@ +package main + +import ( + "encoding/xml" + "fmt" + "html/template" + "io/ioutil" + "net/http" +) + +type NewsMap struct { + Keyword string + Location string +} + +type NewsAggPage struct { + Title string + News map[string]NewsMap +} + +type Sitemapindex struct { + Locations []string `xml:"sitemap>loc"` +} + +type News struct { + Titles []string `xml:"url>news>title"` + Keywords []string `xml:"url>news>keywords"` + Locations []string `xml:"url>loc"` +} + +func indexHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "

Whoa, Go is neat!

") +} + +func newsAggHandler(w http.ResponseWriter, r *http.Request) { + var s Sitemapindex + var n News + resp, _ := http.Get("https://www.washingtonpost.com/news-sitemap-index.xml") + bytes, _ := ioutil.ReadAll(resp.Body) + xml.Unmarshal(bytes, &s) + news_map := make(map[string]NewsMap) + + for _, Location := range s.Locations { + resp, _ := http.Get(Location) + bytes, _ := ioutil.ReadAll(resp.Body) + xml.Unmarshal(bytes, &n) + + for idx, _ := range n.Keywords { + news_map[n.Titles[idx]] = NewsMap{n.Keywords[idx], n.Locations[idx]} + } + } + + p := NewsAggPage{Title: "Amazing News Aggregator", News: news_map} + t, _ := template.ParseFiles("newsaggtemplate.html") + t.Execute(w, p) +} + +func main() { + //http.HandleFunc("/", indexHandler) + http.HandleFunc("/", newsAggHandler) + http.ListenAndServe(":8000", nil) +} From e490e9625982d9065ca66ca31d0d0ae84f4ce173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wojdy=C5=82o?= Date: Wed, 21 Nov 2018 19:39:21 +0000 Subject: [PATCH 4/9] =?UTF-8?q?Usu=C5=84=20'plik.go'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plik.go | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 plik.go diff --git a/plik.go b/plik.go deleted file mode 100644 index da6df8a..0000000 --- a/plik.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - -) - -func hello(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "to dziala :)") -} - - -func main(){ - http.HandleFunc("/", hello) - http.ListenAndServe(":8080", nil) -} \ No newline at end of file From 8c31e310c8bca1fdd6bb4a60fdf76ce5dd29dba9 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Wed, 21 Nov 2018 20:43:02 +0100 Subject: [PATCH 5/9] html --- newsaggtemplate.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 newsaggtemplate.html diff --git a/newsaggtemplate.html b/newsaggtemplate.html new file mode 100644 index 0000000..9a167b4 --- /dev/null +++ b/newsaggtemplate.html @@ -0,0 +1,30 @@ + + + + + + +

{{.Title}}

+ + + + + + + + + + + + {{ range $key, $value := .News }} + + + + + {{ end }} + +
TitleKeywords
{{ $key }}{{ $value.Keyword }}
+ + \ No newline at end of file From 9947c0e266b8523cd1a39e97bc646d242cf01170 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Wed, 21 Nov 2018 20:52:40 +0100 Subject: [PATCH 6/9] html --- basictemplating.html | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 basictemplating.html diff --git a/basictemplating.html b/basictemplating.html new file mode 100644 index 0000000..b7e62f5 --- /dev/null +++ b/basictemplating.html @@ -0,0 +1,2 @@ +

{{ .Titles }}

+

{{ .News }}

From fe5596ffa5d8f1a48877b73b4744446d23842bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wojdy=C5=82o?= Date: Wed, 21 Nov 2018 20:23:41 +0000 Subject: [PATCH 7/9] =?UTF-8?q?Usu=C5=84=20'basictemplating.html'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basictemplating.html | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 basictemplating.html diff --git a/basictemplating.html b/basictemplating.html deleted file mode 100644 index b7e62f5..0000000 --- a/basictemplating.html +++ /dev/null @@ -1,2 +0,0 @@ -

{{ .Titles }}

-

{{ .News }}

From 2cad5c9f1b59233b11c979658287acb6c8187c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wojdy=C5=82o?= Date: Mon, 3 Dec 2018 17:40:35 +0000 Subject: [PATCH 8/9] =?UTF-8?q?Usu=C5=84=20'gotut.go'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gotut.go | 62 -------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100755 gotut.go diff --git a/gotut.go b/gotut.go deleted file mode 100755 index 28527cb..0000000 --- a/gotut.go +++ /dev/null @@ -1,62 +0,0 @@ -package main - -import ( - "encoding/xml" - "fmt" - "html/template" - "io/ioutil" - "net/http" -) - -type NewsMap struct { - Keyword string - Location string -} - -type NewsAggPage struct { - Title string - News map[string]NewsMap -} - -type Sitemapindex struct { - Locations []string `xml:"sitemap>loc"` -} - -type News struct { - Titles []string `xml:"url>news>title"` - Keywords []string `xml:"url>news>keywords"` - Locations []string `xml:"url>loc"` -} - -func indexHandler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "

Whoa, Go is neat!

") -} - -func newsAggHandler(w http.ResponseWriter, r *http.Request) { - var s Sitemapindex - var n News - resp, _ := http.Get("https://www.washingtonpost.com/news-sitemap-index.xml") - bytes, _ := ioutil.ReadAll(resp.Body) - xml.Unmarshal(bytes, &s) - news_map := make(map[string]NewsMap) - - for _, Location := range s.Locations { - resp, _ := http.Get(Location) - bytes, _ := ioutil.ReadAll(resp.Body) - xml.Unmarshal(bytes, &n) - - for idx, _ := range n.Keywords { - news_map[n.Titles[idx]] = NewsMap{n.Keywords[idx], n.Locations[idx]} - } - } - - p := NewsAggPage{Title: "Amazing News Aggregator", News: news_map} - t, _ := template.ParseFiles("newsaggtemplate.html") - t.Execute(w, p) -} - -func main() { - //http.HandleFunc("/", indexHandler) - http.HandleFunc("/", newsAggHandler) - http.ListenAndServe(":8000", nil) -} From 2fbb27f1894fc0d0c785268ec567fe2e0193b800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wojdy=C5=82o?= Date: Mon, 3 Dec 2018 17:40:41 +0000 Subject: [PATCH 9/9] =?UTF-8?q?Usu=C5=84=20'newsaggtemplate.html'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- newsaggtemplate.html | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 newsaggtemplate.html diff --git a/newsaggtemplate.html b/newsaggtemplate.html deleted file mode 100644 index 9a167b4..0000000 --- a/newsaggtemplate.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - -

{{.Title}}

- - - - - - - - - - - - {{ range $key, $value := .News }} - - - - - {{ end }} - -
TitleKeywords
{{ $key }}{{ $value.Keyword }}
- - \ No newline at end of file