Exemplo n.º 1
0
func FetchUrl(theurl string) string {
	var client *http.Client

	if proxy := os.Getenv("http_proxy"); proxy != `` {
		proxyUrl, err := url.Parse(proxy)
		yeasy.CheckError(err)

		transport := http.Transport{
			Dial:  TimeoutDialer(5*time.Second, 5*time.Second), // connect, read/write
			Proxy: http.ProxyURL(proxyUrl),
		}

		client = &http.Client{Transport: &transport}
	} else {
		client = &http.Client{}
	}

	req, err := http.NewRequest(`GET`, theurl, nil)
	yeasy.CheckError(err)

	resp, err := client.Do(req)
	yeasy.CheckError(err)

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	yeasy.CheckError(err)

	return string(body)
}
Exemplo n.º 2
0
func New(port string) {
	wd, err := os.Getwd()
	yeasy.CheckError(err)

	http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir(wd+`/public`))))
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(wd+`/templates`))))

	err = http.ListenAndServe(":"+port, nil)
	yeasy.CheckError(err)
}
Exemplo n.º 3
0
func New() {
	wd, err := os.Getwd()
	yeasy.CheckError(err)

	http.HandleFunc("/", IndexHandler)
	http.HandleFunc("/images/", ImageHandler)
	http.HandleFunc("/media", MediaHandler)

	http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir(wd+`/public`))))

	err = http.ListenAndServe(":9999", nil)
	yeasy.CheckError(err)
}
Exemplo n.º 4
0
func (w *Document) CleanText() {
	asciiregexp, err := regexp.Compile("[^A-Za-z ]+")
	yeasy.CheckError(err)

	tagregexp, err := regexp.Compile("<[^>]+>")
	yeasy.CheckError(err)

	spaceregexp, err := regexp.Compile("[ ]+")
	yeasy.CheckError(err)

	w.SafeText = tagregexp.ReplaceAllString(w.Text, " ")
	w.SafeText = asciiregexp.ReplaceAllString(w.SafeText, " ")
	w.SafeText = spaceregexp.ReplaceAllString(w.SafeText, " ")
	w.SafeText = strings.Trim(w.SafeText, "")
	w.SafeText = strings.ToLower(w.SafeText)
	w.SafeText = strings.TrimSpace(w.SafeText)
}
Exemplo n.º 5
0
func render(filenames ...string) *template.Template {
	t := template.New("layout")
	t.Delims("//", "//")

	t, err := t.ParseFiles(filenames...)
	yeasy.CheckError(err)

	return t
}