Skip to content

Instantly share code, notes, and snippets.

@inhies
Last active December 30, 2015 03:09
Show Gist options
  • Save inhies/7767525 to your computer and use it in GitHub Desktop.
Save inhies/7767525 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"net/http"
"strconv"
)
func handler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
fmt.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var length = 1024
if len(r.Form["length"]) > 0 {
length, err = strconv.Atoi(r.Form["length"][0])
if err != nil {
fmt.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
w.Header().Set("Content-type", "text/plain")
msg := []byte("go is the best, http-kit is weak, clojure can suck it, blah blah blah engrish goes here. ")
bigMsg := bytes.Repeat(msg, 200)
i, err := w.Write(bigMsg[:length])
fmt.Println(i, err)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment