Example of a Go program which reads URL parameters and prints them out

This is an example Go program which demonstrates getting parameters from a form and printing them out.

package main

import (

func reply(rw http.ResponseWriter, req *http.Request) {
        err := req.ParseForm()
        if err != nil {
                rw.Write([]byte(fmt.Sprintf ("Error %s processing request", err)))
<input name='t' type='text'>
<input type='submit'>
        if len(req.Form) > 0 {
                rw.Write([]byte(fmt.Sprintf ("<pre>%s</pre>", req.Form)))

func main() {
        http.HandleFunc("/", reply)
        log.Fatal(http.ListenAndServe(":8082", nil))


Copyright © Ben Bullock 2009-2024. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer