Simple Go Web Page (GET Method)

I wanted to give the Go language a try today for a simple web page that I needed. Unfortunately, I got tripped up when I placed an extra / at the end of my handler. Thought I would post the first working copy here before I go off and finish the page. Hopefully, no one else gets burned by that little mistake.

package main

import (

func summaryHandler(w http.ResponseWriter, r *http.Request) {

   var header = `
    <meta http-equiv="Content-Type" content=\"text/html; charset=utf-8">
    <script src=""
    <script src="/js/myjs.js"></script>

    <link rel="stylesheet" href="/css/dictionary.css">
    fmt.Fprint(w, header)
    fmt.Fprint(w, "<h1>Hello World: Simple Go Web Page</h1>")
    params := r.URL.Query()
    fmt.Fprint(w, r.URL)
    fmt.Fprint(w, params)
    param1 := params["param1"]
    param2 := params["param2"]

    fmt.Fprint(w, "<p>Param1=", param1, "</p>")
    fmt.Fprint(w, "<p>Param2=", param2, "</p>")

func setupWeb() {
    // Put static assets in the resources dir
    http.Handle("/", http.FileServer(http.Dir("resources")))
    // WARNING: "/summary/" will cause pain with the GET
    http.HandleFunc("/summary", summaryHandler)

    err := http.ListenAndServe("localhost:3000", nil)
    if err != nil {

func main() {


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s