Skip to content

Instantly share code, notes, and snippets.

@shonenada
Created September 28, 2013 12:39
Show Gist options
  • Save shonenada/6741682 to your computer and use it in GitHub Desktop.
Save shonenada/6741682 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"strconv"
)
const (
PORT int = 9000
)
func server(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
url := r.URL.Path
fmt.Fprintf(w, "Welcome ~ ~ \n")
fmt.Fprintf(w, "You are visiting: %s\n", url)
fmt.Fprintf(w, "Method: %s\n", r.Method)
if r.Form != nil {
fmt.Fprint(w, "Here are parameters:\n")
for key, value := range r.Form {
fmt.Fprintf(w, "%s => %s", key, value)
}
}
}
func main() {
http.HandleFunc("/", server)
err := http.ListenAndServe(":"+strconv.Itoa(PORT), nil)
if err != nil {
log.Fatal("Fatal:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment