Anchor
2014-12-16 14:06:21 -08:00
605 changed files with 491 additions and 352 deletions

3
LANGS.md Normal file
View File

@@ -0,0 +1,3 @@
* [English](en/)
* [中文](zh/)
* [日本語](ja/)

View File

@@ -1,35 +1,20 @@
# 《Go Web 编程》
这本书目前有多个版本:
# Mulit Language Version
* [English](en/)
* [中文](zh/)
* [日本語](ja/)
[中文开始阅读](<https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/preface.md>)
# Donate
[日文开始阅读](<https://github.com/astaxie/build-web-application-with-golang/blob/master/ja/ebook/preface.md>)
[English Version](<https://github.com/astaxie/build-web-application-with-golang/blob/master/en/eBook/preface.md>)
目前这本书已经出版,如果你觉得内容还可以,你可以通过下面几个途径购买,谢谢支持:
- [chinapub](http://product.china-pub.com/3767290)
- [当当网](http://product.dangdang.com/product.aspx?product_id=23231404)
- [京东](http://book.jd.com/11224644.html)
- [Amazon](http://www.amazon.cn/Go-Web%E7%BC%96%E7%A8%8B-%E8%B0%A2%E5%AD%9F%E5%86%9B/dp/B00CHWVAHQ/ref=sr_1_1?s=books&ie=UTF8&qid=1369323453&sr=1-1)
![](ebook/images/ebook.jpg)
# 通过捐款支持本书
如果你喜欢这本《Go Web编程》的话 可以通过捐款的方式, 支持作者继续更新本书或者做出其他更多好玩好用的开源应用: 比如为本书修补漏洞、添加更多有趣的章节, 或者发行有更多更棒内容的下一版或者改善beego等等。
支付宝扫描捐款: ![](ebook/images/alipay.png)
AliPay: <img src="zh/images/alipay.png" alt="alipay" width="100" height="100">
English Donate:[donate](http://beego.me/donate)
## 交流
欢迎大家加入QQ群259316004 《Go Web编程》专用交流群
## Community
QQ群386056972
论坛交流[http://bbs.go-china.org/](http://bbs.go-china.org/)
BBS[http://golanghome.com/](http://golanghome.com/)
## 致谢
首先要感谢Golang-China的QQ群102319854(已满)请加2群(384414723),里面的每一个人都很热心,同时要特别感谢几个人
## Acknowledgments
- [四月份平民](https://plus.google.com/110445767383269817959) (review代码)
- [Hong Ruiqi](https://github.com/hongruiqi) (review代码)
@@ -39,11 +24,9 @@ English Donate:[donate](http://beego.me/donate)
- [polaris](https://github.com/polaris1119)(review书)
- [雨痕](https://github.com/qyuhen)(review第二章)
## 授权许可
除特别声明外,本书中的内容使用[CC BY-SA 3.0 License](http://creativecommons.org/licenses/by-sa/3.0/)(创作共用 署名-相同方式共享3.0许可协议)授权,代码遵循[BSD 3-Clause License](<https://github.com/astaxie/build-web-application-with-golang/blob/master/LICENSE.md>)3项条款的BSD许可协议
## License
Book License: [CC BY-SA 3.0 License](http://creativecommons.org/licenses/by-sa/3.0/)
## 开始阅读
[开始阅读](<https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/preface.md>)
Code License: [BSD 3-Clause License](<https://github.com/astaxie/build-web-application-with-golang/blob/master/LICENSE.md>)
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/44c98c9d398b8319b6e87edcd3e34144 "githalytics.com")](http://githalytics.com/astaxie/build-web-application-with-golang)

View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@@ -115,7 +115,7 @@ That's all? No! Go supports complex numbers as well. `complex128` (with a 64-bit
### String
We just talked about how Go uses the UTF-8 character set. Strings are represented by double quotes `""` or backtracks ``` `.
We just talked about how Go uses the UTF-8 character set. Strings are represented by double quotes `""` or backticks ``` `` ```.
// sample code
var frenchHello string // basic form to define string

View File

@@ -271,7 +271,7 @@ Let's use an example to see more clearly.
} else if value, ok := element.(Person); ok {
fmt.Printf("list[%d] is a Person and its value is %s\n", index, value)
} else {
fmt.Println("list[%d] is of a different type", index)
fmt.Printf("list[%d] is of a different type\n", index)
}
}
}

View File

@@ -2,7 +2,7 @@
Every time you open your browsers, type some URLs and press enter, you will see beautiful web pages appear on your screen. But do you know what is happening behind these simple actions?
Normally, your browser is a client. After you type a URL, it sends your request to a DNS server in order to get the IP address of that URL. Then it finds the server in that IP address and asks to setup TCP connections. When the browser is finished sending HTTP requests, the server starts handling your request packages, then returns HTTP response packages to your browser. Finally, the browser renders bodies of the web pages and disconnects from the server.
Normally, your browser is a client. After you type a URL, it takes the host part of the URL and sends it to a DNS server in order to get the IP address of the host. Then it connects to the IP address and asks to setup a TCP connection. The browser sends HTTP requests through the connection. The server server handles them and replies with HTTP responses containing the content that make up the web page. Finally, the browser renders bodies of the web pages and disconnects from the server.
![](images/3.1.web2.png?raw=true)

View File

@@ -6,7 +6,7 @@ PostgreSQL is an object-relational database management system available for many
There are many database drivers available for PostgreSQL. Here are three examples of them:
- [https://github.com/bmizerany/pq](https://github.com/bmizerany/pq) supports `database/sql`, written in pure Go.
- [https://github.com/bmizerany/pq](https://github.com/lib/pq) supports `database/sql`, written in pure Go.
- [https://github.com/jbarham/gopgsqldriver](https://github.com/jbarham/gopgsqldriver) supports `database/sql`, written in pure Go.
- [https://github.com/lxn/go-pgsql](https://github.com/lxn/go-pgsql) supports `database/sql`, written in pure Go.
@@ -33,7 +33,7 @@ An example:
import (
"database/sql"
"fmt"
_ "github.com/bmizerany/pq"
_ "github.com/lib/pq"
"time"
)

View File

@@ -60,8 +60,7 @@ Go uses the `SetCookie` function in the `net/http` package to set cookies:
Here is an example of setting a cookie:
expiration := *time.LocalTime()
expiration.Year += 1
expiration := time.Now().Add(365 * 24 * time.Hour)
cookie := http.Cookie{Name: "username", Value: "astaxie", Expires: expiration}
http.SetCookie(w, &cookie)
  

View File

@@ -266,7 +266,7 @@ Some of you may be thinking the following: this server does not do anything mean
func handleClient(conn net.Conn) {
conn.SetReadDeadline(time.Now().Add(2 * time.Minute)) // set 2 minutes timeout
request := make([]byte, 128) // set maxium request length to 128KB to prevent flood based attacks
request := make([]byte, 128) // set maximum request length to 128KB to prevent flood based attacks
defer conn.Close() // close connection before exit
for {
read_len, err := conn.Read(request)

View File

@@ -40,7 +40,7 @@ But we can see some implementations daemon many online methods, such as the foll
- Another solution is to use the syscall, but this solution is not perfect:
<pre>
```
package main
import (
@@ -109,7 +109,7 @@ But we can see some implementations daemon many online methods, such as the foll
return 0
}
</pre>
```
The above proposed two implementations Go's daemon program, but I still do not recommend you to realize this, because the official announcement has not officially support daemon, of course, the first option is more feasible for now, but it is currently open source library skynet in adopting this program do daemon.

View File

@@ -1,26 +1,6 @@
***Build Web Application with Golang***
======================================
[Download PDF](https://drive.google.com/file/d/0B2GBHFyTK2N8TzM4dEtIWjBJdEk/edit?usp=sharing)
### ***Translator Comments***
This is an English version of [《Go Web编程》](https://github.com/astaxie/build-web-application-with-golang), the original version was written by [AstaXie](https://github.com/astaxie) and translated by [Unknwon](https://github.com/Unknwon) and [Larry Battle](https://github.com/LarryBattle).
This book is about how to build web applications in Go. In the first few chapters of the book, the author will review some basic knowledge about Go. However, for an optimal reading experience, you should have a basic understanding of the Go language and the concept of a web application. If you are completely new to programming, this book is not intended to provide sufficient introductory material to get started.
If anything is unclear due to wording or language issues, feel free to ask me to write a better translation.
###Acknowledgments for translation help
- [matalangilbert](https://github.com/matalangilbert)
- [nightlyone](https://github.com/nightlyone)
- [sbinet](https://github.com/sbinet)
- [carbocation](https://github.com/carbocation)
- [desimone](https://github.com/desimone)
- [reigai](https://github.com/reigai)
- [OlingCat](https://github.com/OlingCat)
### Purpose
Because I'm interested in web application development, I used my free time to write this book as an open source version. It doesn't mean that I have a very good ability to build web applications; I would like to share what I've done with Go in building web applications.
@@ -30,18 +10,19 @@ Because I'm interested in web application development, I used my free time to wr
I believe the purpose of studying is sharing with others. The happiest thing in my life is sharing everything I've known with more people.
### Donation
# Donate
If you like this book, you can ask your Chinese friends to follow this [link](https://me.alipay.com/astaxie) donate the original author, help him write more books with better, more useful, and more interesting content.
AliPay: <img src="../zh/images/alipay.png" alt="alipay" width="100" height="100">
### Exchanging Learning Go
English Donate:[donate](http://beego.me/donate)
If you know what is QQ, join the group 259316004. If not, follow this [link](http://download.imqq.com/download.shtml) to get more details. Also, you can join our [forum](http://bbs.beego.me).
## Community
QQ群386056972
BBS[http://golanghome.com/](http://golanghome.com/)
### Acknowledgments
First, I have to thank the people who are members of Golang-China in QQ group 102319854, they are all very nice and helpful. Then, I need to thank the following people who gave great help when I was writing this book.
- [四月份平民 April Citizen](https://plus.google.com/110445767383269817959) (review code)
- [洪瑞琦 Hong Ruiqi](https://github.com/hongruiqi) (review code)
- [边 疆 BianJiang](https://github.com/border) (write the configurations about Vim and Emacs for Go development)
@@ -54,7 +35,3 @@ First, I have to thank the people who are members of Golang-China in QQ group 10
This book is licensed under the [CC BY-SA 3.0 License](http://creativecommons.org/licenses/by-sa/3.0/),
the code is licensed under a [BSD 3-Clause License](<https://github.com/astaxie/build-web-application-with-golang/blob/master/LICENSE.md>), unless otherwise specified.
### Get Started
[Index](./eBook/preface.md)

96
en/SUMMARY.md Normal file
View File

@@ -0,0 +1,96 @@
* [Go Environment Configuration](01.0.md)
* [Installation](01.1.md)
* [$GOPATH and workspace](01.2.md)
* [Go commands](01.3.md)
* [Go development tools](01.4.md)
* [Summary](01.5.md)
* [Go basic knowledge](02.0.md)
* [Hello, Go](02.1.md)
* [Go foundation](02.2.md)
* [Control statements and functions](02.3.md)
* [struct](02.4.md)
* [Object-oriented](02.5.md)
* [interface](02.6.md)
* [Concurrency](02.7.md)
* [Summary](02.8.md)
* [Web foundation](03.0.md)
* [Web working principles](03.1.md)
* [Build a simple web server](03.2.md)
* [How Go works with web](03.3.md)
* [Get into http package](03.4.md)
* [Summary](03.5.md)
* [HTTP Form](04.0.md)
* [Process form inputs](04.1.md)
* [Validation of inputs](04.2.md)
* [Cross site scripting](04.3.md)
* [Duplicate submissions](04.4.md)
* [File upload](04.5.md)
* [Summary](04.6.md)
* [Database](05.0.md)
* [database/sql interface](05.1.md)
* [How to use MySQL](05.2.md)
* [How to use SQLite](05.3.md)
* [How to use PostgreSQL](05.4.md)
* [How to use beedb ORM](05.5.md)
* [NOSQL](05.6.md)
* [Summary](05.7.md)
* [Data storage and sessions](06.0.md)
* [session和cookie](06.1.md)
* [Go如何使用session](06.2.md)
* [session存储](06.3.md)
* [预防session劫持](06.4.md)
* [Summary](06.5.md)
* [文本文件处理](07.0.md)
* [XML处理](07.1.md)
* [JSON处理](07.2.md)
* [正则处理](07.3.md)
* [模板处理](07.4.md)
* [文件操作](07.5.md)
* [字符串处理](07.6.md)
* [Summary](07.7.md)
* [Web服务](08.0.md)
* [Socket编程](08.1.md)
* [WebSocket](08.2.md)
* [REST](08.3.md)
* [RPC](08.4.md)
* [小结](08.5.md)
* [安全与加密](09.0.md)
* [预防CSRF攻击](09.1.md)
* [确保输入过滤](09.2.md)
* [避免XSS攻击](09.3.md)
* [避免SQL注入](09.4.md)
* [存储密码](09.5.md)
* [加密和解密数据](09.6.md)
* [小结](09.7.md)
* [国际化和本地化](10.0.md)
* [设置默认地区](10.1.md)
* [本地化资源](10.2.md)
* [国际化站点](10.3.md)
* [小结](10.4.md)
* [错误处理,调试和测试](11.0.md)
* [错误处理](11.1.md)
* [使用GDB调试](11.2.md)
* [Go怎么写测试用例](11.3.md)
* [小结](11.4.md)
* [部署与维护](12.0.md)
* [应用日志](12.1.md)
* [网站错误处理](12.2.md)
* [应用部署](12.3.md)
* [备份和恢复](12.4.md)
* [小结](12.5.md)
* [如何设计一个Web框架](13.0.md) 
* [项目规划](13.1.md) 
* [自定义路由器设计](13.2.md)
* [controller设计](13.3.md)
* [日志和配置设计](13.4.md)
* [实现博客的增删改](13.5.md)
* [小结](13.6.md) 
* [扩展Web框架](14.0.md)
* [静态文件支持](14.1.md)
* [Session支持](14.2.md)
* [表单支持](14.3.md)
* [用户认证](14.4.md)
* [多语言支持](14.5.md)
* [pprof支持](14.6.md)
* [小结](14.7.md)
* [参考资料](ref.md)

Some files were not shown because too many files have changed in this diff Show More