Jump to content

Server-Side Scripting/Introduction/Go

From Wikiversity

app.go

[edit | edit source]
// Displays "Hello world!"
//
// References:
//  https://repl.it/@mauriycf/A-simple-web-server-in-go#main.go
//  https://gowebexamples.com/hello-world/

package main

import (
    "net/http"
    "io"
)

func handler(response http.ResponseWriter, request *http.Request) {
    io.WriteString(response, "Hello world!")
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8000", nil)
}

Try It

[edit | edit source]

Copy and paste the code above into the following free online development environment or use your own Go compiler / interpreter / IDE.

See Also

[edit | edit source]