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

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.

主站蜘蛛池模板: 梅河口市| 马边| 曲麻莱县| 盐边县| 临城县| 综艺| 河北省| 昭平县| 义马市| 新蔡县| 泉州市| 大同县| 田东县| 武夷山市| 安图县| 广平县| 内江市| 霞浦县| 永平县| 云和县| 万山特区| 绥芬河市| 苏州市| 同德县| 曲阜市| 陈巴尔虎旗| 哈密市| 建湖县| 桃园县| 靖安县| 潼南县| 木里| 涡阳县| 米林县| 玛曲县| 宝应县| 鄱阳县| 云阳县| 遂宁市| 文昌市| 榆林市|