Hello world/Web server

From Rosetta Code
Revision as of 20:53, 30 June 2011 by Sonia (talk | contribs) (New task: Hello world/Web server)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Hello world/Web server is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task
Hello world/Web server
You are encouraged to solve this task according to the task description, using any language you may know.

The browser is the new GUI!

Serve our standard text "Goodbye, World!" to http://localhost:8080/ so that it can be viewed with a web browser.

Starting a web browser or opening a new window with this URL is not part of the task. Also you do not need to bother serving proper HTML, as browsers generally do the right thing with simple text like this. Your program must however, start or implement a server that accepts multiple client connections and serves text as requested.

Go

<lang go>package main

import (

   "http"
   "fmt"

)

func main() {

   http.HandleFunc("/",
       func(w http.ResponseWriter, req *http.Request) {
           fmt.Fprintln(w, "Goodbye, World!")
       })
   if err := http.ListenAndServe(":8080", nil); err != nil {
       fmt.Println(err)
   }

}</lang>