The creation of the HTTP server in Go is very easy, and the standard library provides more ways of how to do that. Let's look at the very basic one.
Creating the HTTP Server
How to do it...
- Open the console and create the folder chapter09/recipe04.
- Navigate to the directory.
- Create the httpserver.go file with the following content:
package main
import (
"fmt"
"net/http"
)
type SimpleHTTP struct{}
func (s SimpleHTTP) ServeHTTP(rw http.ResponseWriter,
r *http.Request) {
fmt.Fprintln(rw, "Hello world")
}
func main() {
fmt.Println("Starting HTTP server on port 8080")
...