-
Notifications
You must be signed in to change notification settings - Fork 0
/
aboutpage.go
49 lines (39 loc) · 929 Bytes
/
aboutpage.go
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
package main
import (
"html/template"
"net/http"
"io"
"log"
"github.com/ccaneke/webAnalytics/webAnalyzer"
)
func loadPage(url string) (io.Reader, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
return resp.Body, nil
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *webAnalyzer.PageInformation) {
t, _ := template.ParseFiles(tmpl + ".html")
t.Execute(w, p)
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
renderTemplate(w, "index", nil)
}
func viewHandler(w http.ResponseWriter, r *http.Request) {
url := r.FormValue("htmlversion")
reader, err := loadPage(url)
if err != nil {
return
}
pgInfo, err := webAnalyzer.GetPageInformation(reader)
if err != nil {
return
}
renderTemplate(w, "view", &pgInfo)
}
func main() {
http.HandleFunc("/index/", indexHandler)
http.HandleFunc("/view/", viewHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}