上QQ阅读APP看书,第一时间看更新
Running the code
We can run the preceding code as a standalone program. Name the preceding program basicHandler.go. Store it anywhere you wish to, then run it using the following command:
go run basicHandler.go
Now fire up a shell or browser to see the server in action. Here, I use the CURL request:
curl -X GET http://localhost:8000/hello
The response is:
hello, world
Go has a different concept for handling request and response. We used the io library to write to the response. For web development, we can use a template to automatically fill in the details. Go's internal URL handlers use a ServeMux multiplexer.