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

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

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

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

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

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

	defer resp.Body.Close()

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

	return string(body)
}
Ejemplo n.º 2
0
func main() {
	wd, err := os.Getwd()
	sir.CheckError(err)

	http.HandleFunc("/", IndexHandler)
	http.HandleFunc("/add", AddHandler)
	http.HandleFunc("/test", TestHandler)
	http.HandleFunc("/search", SearchHandler)

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

	err = http.ListenAndServe(":8080", nil)
	sir.CheckError(err)
}
Ejemplo n.º 3
0
func main() {
	if len(os.Args) < 1 {
		log.Fatal("not enough args")
	}

	max := 0

	for i := 1; i < len(os.Args); i++ {
		arg, err := strconv.Atoi(os.Args[i])

		sir.CheckError(err)

		if arg > max {
			max = arg
		}
	}

	if len(os.Args[1:]) < max {
		log.Fatal(max, " points to a location not in the array")
	}

	log.Println(max)

	f = make([]int, 0)

	for i := 1; i < len(os.Args); i++ {
		arg, err := strconv.Atoi(os.Args[i])

		sir.CheckError(err)

		f = append(f, arg)
	}

	log.Println("\t", "[start pos]", "[cycle start pos]", "[cycle len]")

	for i := 0; i < len(f); i++ {
		fpos, flen := floyd(i)
		log.Println("floyd", i, "\t", fpos, "\t", flen)

		bpos, blen := brent(i)
		log.Println("brent", i, "\t", bpos, "\t", blen)

		if fpos != bpos || flen != blen {
			log.Fatal("[error]", "floyd and brent do not agree!")
		}
	}

	log.Println(f)
}
Ejemplo n.º 4
0
func (r Response) String() string {
	b, err := json.Marshal(r)

	sir.CheckError(err)

	return string(b)
}
Ejemplo n.º 5
0
func (w *Document) CleanText() {
	asciiregexp, err := regexp.Compile("[^A-Za-z ]+")
	sir.CheckError(err)

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

	spaceregexp, err := regexp.Compile("[ ]+")
	sir.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)
}
Ejemplo n.º 6
0
func Render(filenames ...string) *template.Template {
	t := template.New("layout")
	t.Delims("//", "//")

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

	return t
}