Skip to content

Instantly share code, notes, and snippets.

@newtonapple
Created June 7, 2010 23:13
Show Gist options
  • Save newtonapple/429327 to your computer and use it in GitHub Desktop.
Save newtonapple/429327 to your computer and use it in GitHub Desktop.
// returns "hello world\n"
// 6g http_server.go
// 6l http_server.6
// ./6.out
// benchmark w/ Apache Bench
// ab -n 2000 -c 200 http://localhost:1234/
package main
import (
"flag"
"http"
"io"
"log"
)
func main() {
addr := flag.String("addr", ":1234", "http service address")
flag.Parse()
http.Handle( "/", http.HandlerFunc(HelloWorld) )
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Exit("ListenAndServe: ", err)
}
}
func HelloWorld(c *http.Conn, req *http.Request) {
io.WriteString(c, "hello world\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment