Skip to content

Commit c590132

Browse files
author
Shuaiying Hou
committed
Merge pull request astaxie#1 from astaxie/master
Update from head repo
2 parents 8feb49d + 1dfcbc6 commit c590132

File tree

13 files changed

+47
-32
lines changed

13 files changed

+47
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*~
22
pkg/*
33
*.html
4+
*.exe
45

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# 《Go Web 编程》
2-
因为自己对Web开发比较感兴趣,所以最近抽空在写一本开源的书籍《Go Web编程》《Build Web Application with Golang》。写这本书不表示我能力很强,而是我愿意分享,和大家一起分享Go写Web应用的一些东西。
2+
目前这本书已经出版,如果你觉得内容还可以,你可以通过下面几个途径购买,谢谢支持:
33

4-
- 对于从PHP/Python/Ruby转过来的同学了解Go怎么写Web应用开发的
4+
- [chinapub](http://product.china-pub.com/3767290)
5+
- [当当网](http://product.dangdang.com/product.aspx?product_id=23231404)
6+
- [京东](http://book.jd.com/11224644.html)
7+
- [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)
58

6-
- 对于从C/C++转过来的同学了解Web到底是怎么运行起来的
7-
8-
我一直认为知识是用来分享的,让更多的人分享自己拥有的一切知识这个才是人生最大的快乐。
9-
10-
这本书目前我放在Github上,我现在基本每天晚上抽空会写一些,时间有限、能力有限,所以希望更多的朋友参与到这个开源项目中来。
9+
![](ebook/images/ebook.jpg)
1110

1211
# 通过捐款支持本书
1312
如果你喜欢这本《Go Web编程》的话, 可以通过捐款的方式, 支持作者继续更新本书或者做出其他更多好玩好用的开源应用: 比如为本书修补漏洞、添加更多有趣的章节, 或者发行有更多更棒内容的下一版,或者改善beego等等。

ebook/01.1.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,29 @@ gvm是第三方开发的Go多版本管理工具,类似ruby里面的rvm工具
114114

115115
安装完成后我们就可以安装go了:
116116

117-
gvm install go1.0.3
118-
gvm use go1.0.3
117+
gvm install go1.1
118+
gvm use go1.1
119119

120+
也可以使用下面的命令,省去每次调用gvm use的麻烦:
121+
gvm use go1.1 --default
122+
120123
执行完上面的命令之后GOPATH、GOROOT等环境变量会自动设置好,这样就可以直接使用了。
121124

122125
### apt-get
123-
Ubuntu是目前使用最多的Linux桌面系统,使用`apt-get`命令来管理软件包,我们可以通过下面的命令来安装Go:
126+
Ubuntu是目前使用最多的Linux桌面系统,使用`apt-get`命令来管理软件包,我们可以通过下面的命令来安装Go,为了以后方便,应该把 `git` `mercurial` 也安装上
124127

128+
sudo apt-get install python-software-properties
125129
sudo add-apt-repository ppa:gophers/go
126130
sudo apt-get update
127-
sudo apt-get install golang-stable
131+
sudo apt-get install golang-stable git-core mercurial
128132

129133
### homebrew
130-
homebrew是Mac系统下面目前使用最多的管理软件的工具,目前已支持Go,可以通过命令直接安装Go:
134+
homebrew是Mac系统下面目前使用最多的管理软件的工具,目前已支持Go,可以通过命令直接安装Go,为了以后方便,应该把 `git` `mercurial` 也安装上
131135

136+
brew update && brew upgrade
132137
brew install go
138+
brew install git
139+
brew install mercurial
133140

134141

135142
## links

ebook/01.2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
```sh
1010
export GOPATH=/home/apple/mygo
1111
```
12+
为了方便,应该把新建以上文件夹,并且把以上一行加入到 `.bashrc` 或者 `.zshrc` 或者自己的 `sh` 的配置文件中。
13+
1214
Windows 设置如下,新建一个环境变量名称叫做GOPATH:
1315
```sh
1416
GOPATH=c:\mygo

ebook/01.4.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@
149149

150150
如果没有出现这样的提示,一般就是你的`$PATH`没有配置正确。你可以打开终端,输入gocode,是不是能够正确运行,如果不行就说明`$PATH`没有配置正确。
151151

152+
4. MacOS下已经设置了$GOROOT, $GOPATH, $GOBIN,还是没有自动提示怎么办。
153+
154+
请在sublime中使用command + 9, 然后输入env检查$PATH, GOROOT, $GOPATH, $GOBIN等变量, 如果没有请采用下面的方法。
155+
156+
首先建立下面的连接, 然后从Terminal中直接启动sublime
157+
158+
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
159+
152160

153161
## Vim
154162
Vim是从vi发展出来的一个文本编辑器, 代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。

ebook/02.5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ method的语法如下:
276276
}
277277

278278
### method重写
279-
上面的例子中,如果Emplyee想要实现自己的SayHi,怎么办?简单,和匿名字段冲突一样的道理,我们可以在Emplyee上面定义一个method,重写了匿名字段的方法。请看下面的例子
279+
上面的例子中,如果Employee想要实现自己的SayHi,怎么办?简单,和匿名字段冲突一样的道理,我们可以在Employee上面定义一个method,重写了匿名字段的方法。请看下面的例子
280280

281281
package main
282282
import "fmt"

ebook/04.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title></title>
88
</head>
99
<body>
10-
<form action="http://127.0.0.1:9090/login" method="post">
10+
<form action="/login" method="post">
1111
用户名:<input type="text" name="username">
1212
密码:<input type="password" name="password">
1313
<input type="submit" value="登陆">

ebook/05.2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## MySQL驱动
55
Go中支持MySQL的驱动目前比较多,有如下几种,有些是支持database/sql标准,而有些是采用了自己的实现接口,常用的有如下几种:
66

7-
- https://github.com/Go-SQL-Driver/MySQL 支持database/sql,全部采用go写。
7+
- https://github.com/go-sql-driver/mysql 支持database/sql,全部采用go写。
88
- https://github.com/ziutek/mymysql 支持database/sql,也支持自定义的接口,全部采用go写。
99
- https://github.com/Philio/GoMySQL 不支持database/sql,自定义接口,全部采用go写。
1010

@@ -114,7 +114,7 @@ Go中支持MySQL的驱动目前比较多,有如下几种,有些是支持data
114114

115115
关键的几个函数我解释一下:
116116

117-
sql.Open()函数用来打开一个注册过的数据库驱动,Go-MySQL-Driver中注册了mysql这个数据库驱动,第二个参数是DNS(Data Source Name),它是Go-MySQL-Driver定义的一些数据库链接和配置信息。它支持如下格式:
117+
sql.Open()函数用来打开一个注册过的数据库驱动,Go-MySQL-Driver中注册了mysql这个数据库驱动,第二个参数是DSN(Data Source Name),它是Go-MySQL-Driver定义的一些数据库链接和配置信息。它支持如下格式:
118118

119119
user@unix(/path/to/socket)/dbname?charset=utf8
120120
user:password@tcp(localhost:5555)/dbname?charset=utf8

ebook/06.2.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ Go实现整个的流程应该也是这样的,在main包中创建一个全局
8181

8282
>以上设计思路来源于database/sql/driver,先定义好接口,然后具体的存储session的结构实现相应的接口并注册后,相应功能这样就可以使用了,以下是用来随需注册存储session的结构的Register函数的实现。
8383
84-
var provides = make(map[string]Provide)
84+
var provides = make(map[string]Provider)
8585

8686
// Register makes a session provide available by the provided name.
8787
// If Register is called twice with the same name or if driver is nil,
8888
// it panics.
89-
func Register(name string, provide Provide) {
90-
if driver == nil {
89+
func Register(name string, provider Provider) {
90+
if provider == nil {
9191
panic("session: Register provide is nil")
9292
}
9393
if _, dup := provides[name]; dup {
9494
panic("session: Register called twice for provide " + name)
9595
}
96-
provides[name] = provide
96+
provides[name] = provider
9797
}
9898

9999
### 全局唯一的Session ID

ebook/07.2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ JSON(Javascript Object Notation)是一种轻量级的数据交换语言,
8888
fmt.Println(k, "is string", vv)
8989
case int:
9090
fmt.Println(k, "is int", vv)
91+
case float64:
92+
fmt.Println(k,"is float64",vv)
9193
case []interface{}:
9294
fmt.Println(k, "is an array:")
9395
for i, u := range vv {

0 commit comments

Comments
 (0)