官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 象山县| 曲沃县| 兴业县| 天等县| 秦皇岛市| 商南县| 东港市| 明溪县| 德阳市| 克山县| 永春县| 海林市| 德惠市| 东港市| 东乡族自治县| 花垣县| 剑川县| 壶关县| 榆社县| 平邑县| 张家界市| 福鼎市| 汤原县| 宽甸| 永德县| 西乡县| 揭西县| 九江市| 新巴尔虎右旗| 银川市| 志丹县| 上栗县| 古浪县| 黑水县| 黑龙江省| 永顺县| 云龙县| 河北区| 马龙县| 三河市| 孟州市|