8
1.4.md
8
1.4.md
@@ -250,19 +250,19 @@ Eclipse也是非常常用的开发利器,以下介绍如何使用Eclipse来编
|
||||
|
||||
2.下载[goeclipse](https://code.google.com/p/goclipse/)插件
|
||||
|
||||
http://code.google.com/p/goclipse/wiki/InstallationInstructions
|
||||
http://code.google.com/p/goclipse/wiki/InstallationInstructions
|
||||
|
||||
3.下载gocode,用于go的代码补全提示
|
||||
|
||||
gocode的github地址:
|
||||
|
||||
https://github.com/nsf/gocode
|
||||
https://github.com/nsf/gocode
|
||||
|
||||
在windows下要安装git,通常用[msysgit](https://code.google.com/p/msysgit/)
|
||||
|
||||
再在cmd下安装:
|
||||
|
||||
go get -u github.com/nsf/gocode
|
||||
go get -u github.com/nsf/gocode
|
||||
|
||||
也可以下载代码,直接用go build来编译,会生成gocode.exe
|
||||
|
||||
@@ -270,7 +270,7 @@ gocode的github地址:
|
||||
|
||||
5.配置插件
|
||||
|
||||
Windows->Reference->Go
|
||||
Windows->Reference->Go
|
||||
|
||||
(1).配置Go的编译器
|
||||
|
||||
|
||||
34
3.4.md
34
3.4.md
@@ -111,45 +111,45 @@ handler是一个接口,但是前一小节中的`sayhelloName`函数并没有
|
||||
|
||||
按顺序做了几件事:
|
||||
|
||||
1. 调用了DefaultServerMux的HandleFunc
|
||||
1. 调用了DefaultServerMux的HandleFunc
|
||||
|
||||
2. 调用了DefaultServerMux的Handle
|
||||
2. 调用了DefaultServerMux的Handle
|
||||
|
||||
3. 往DefaultServeMux的map[string]muxEntry中增加对应的handler和路由规则
|
||||
3. 往DefaultServeMux的map[string]muxEntry中增加对应的handler和路由规则
|
||||
|
||||
- 其次调用http.ListenAndServe(":9090", nil)
|
||||
|
||||
按顺序做了几件事情:
|
||||
|
||||
1. 实例化Server
|
||||
1. 实例化Server
|
||||
|
||||
2. 调用Server的ListenAndServe()
|
||||
2. 调用Server的ListenAndServe()
|
||||
|
||||
3. 调用net.Listen("tcp", addr)监听端口
|
||||
3. 调用net.Listen("tcp", addr)监听端口
|
||||
|
||||
4. 启动一个for循环,在循环体中Accept请求
|
||||
4. 启动一个for循环,在循环体中Accept请求
|
||||
|
||||
5. 对每个请求实例化一个Conn,并且开启一个goroutine为这个请求进行服务go c.serve()
|
||||
5. 对每个请求实例化一个Conn,并且开启一个goroutine为这个请求进行服务go c.serve()
|
||||
|
||||
6. 读取每个请求的内容w, err := c.readRequest()
|
||||
6. 读取每个请求的内容w, err := c.readRequest()
|
||||
|
||||
7. 判断handler是否为空,如果没有设置handler(这个例子就没有设置handler),handler就设置为DefaultServeMux
|
||||
7. 判断handler是否为空,如果没有设置handler(这个例子就没有设置handler),handler就设置为DefaultServeMux
|
||||
|
||||
8. 调用handler的ServeHttp
|
||||
8. 调用handler的ServeHttp
|
||||
|
||||
9. 在这个例子中,下面就进入到DefaultServerMux.ServeHttp
|
||||
9. 在这个例子中,下面就进入到DefaultServerMux.ServeHttp
|
||||
|
||||
10. 根据request选择handler,并且进入到这个handler的ServeHTTP
|
||||
10. 根据request选择handler,并且进入到这个handler的ServeHTTP
|
||||
|
||||
mux.handler(r).ServeHTTP(w, r)
|
||||
|
||||
11 选择handler:
|
||||
11 选择handler:
|
||||
|
||||
A. 判断是否有路由能满足这个request(循环遍历ServerMux的muxEntry)
|
||||
A. 判断是否有路由能满足这个request(循环遍历ServerMux的muxEntry)
|
||||
|
||||
B. 如果有路由满足,调用这个路由handler的ServeHttp
|
||||
B. 如果有路由满足,调用这个路由handler的ServeHttp
|
||||
|
||||
C. 如果没有路由满足,调用NotFoundHandler的ServeHttp
|
||||
C. 如果没有路由满足,调用NotFoundHandler的ServeHttp
|
||||
|
||||
## links
|
||||
* [目录](<preface.md>)
|
||||
|
||||
Reference in New Issue
Block a user