GO语言练习:实现最简单的http helloword 服务器
2015-07-22 00:39
513 查看
用Go语言实现一个最简单的http服务器端,主要用到了package io, log, net/http 这个3个库。
用到的函数包括:
http.Handle()
http.HandlerFunc()
http.ListenAndServe()
目录:
1、代码
2、运行
1、代码
$ cat helloserver.go
2、运行
2.1)服务器端
2.2)客户端(浏览器)
用到的函数包括:
http.Handle()
http.HandlerFunc()
http.ListenAndServe()
目录:
1、代码
2、运行
1、代码
$ cat helloserver.go
package main import ( "io" "log" "net/http" "strconv" "fmt" ) var iCnt int = 0; func helloHandler(w http.ResponseWriter, r * http.Request) { iCnt++; str := "Hello world ! friend(" + strconv.Itoa(iCnt) + ")" io.WriteString(w, str) fmt.Println(str) } func main() { ht := http.HandlerFunc(helloHandler) if ht != nil { http.Handle("/hello", ht) } err := http.ListenAndServe(":8090", nil) if err != nil { log.Fatal("ListenAndServe: ", err.Error()) } }
2、运行
2.1)服务器端
2.2)客户端(浏览器)
相关文章推荐
- 在Lighttpd服务器中运行Django应用的方法
- 网络工程师30个经典的电脑使用技巧
- 解决IISASP调用XmlHTTP出现msxml3.dll (0x80070005) 拒绝访问的错误
- 解决IISASP调用XmlHTTP出现msxml3.dll (0x80070005) 拒绝访问的错误
- 如何使用谷歌的网页删除请求工具?
- 今天实在忍不住,把极速星空的密码给破了
- 准备开发一个PSP专用的网站http://www.mypsp.com.cn
- WireShark 网络包过滤
- C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)【转】
- 解决网络通信中的中文乱码问题(Java)
- keepalived+lvs 实现tcp负载均衡
- HTTP Status 500 - org.apache.jasper.JasperException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException
- 使用httpFS访问hdfs
- VMware网络模式介绍
- Meta http-equiv属性详解(转)
- 设定软件使用期限,根据网络时间保护试用软件产品的方法
- 网络拓扑
- 网络带宽不足引起arc进程争用导致两个standby失败
- TCP和UDP的区别以及tcp3次握手和4次挥手。
- 抓取网页信息,下载网络图片到本地