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

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.

主站蜘蛛池模板: 腾冲县| 武威市| 柯坪县| 合阳县| 泰和县| 贵港市| 阿瓦提县| 阿尔山市| 上饶市| 鄂尔多斯市| 思茅市| 阳原县| 石景山区| 临颍县| 四平市| 紫金县| 马边| 蓝山县| 雷州市| 宁南县| 永吉县| 新建县| 鹰潭市| 内黄县| 佛坪县| 宿松县| 奉贤区| 乌鲁木齐县| 三穗县| 汽车| 桂林市| 凤山县| 嵊州市| 米易县| 扎赉特旗| 子长县| 昌平区| 象州县| 镇江市| 冀州市| 永泰县|