失效链接处理 |
Go Web Programming PDF 下载
下载地址:
版权归出版社和原作者所有,链接已删除,请购买正版
用户下载说明:
电子版仅供预览,下载后24小时内务必删除,支持正版,喜欢的请购买正版书籍:
http://product.dangdang.com/1760275605.html
相关截图: ![]() 资料目录:
1 G O AND WEB APPLICATIONS ............................. 1
1
Go and web applications 3
1.1 Using Go for web applications 4
Scalable web applications and Go 4
■
Modular web
applications and Go 5
■
Maintainable web applications and
Go 5
■
High performing web applications and Go 6
1.2 How web applications work 6
1.3 A quick introduction to HTTP 8
1.4 The coming of web applications 8
1.5 HTTP request 9
Request methods 10
■
Safe request methods 11
■
Idempotent
request methods 11
■
Browser support for request methods 11
Request headers 11
CONTENTS viii
1.6 HTTP response 12
Response status code 13
■
Response headers 13
1.7 URI 14
1.8 Introducing HTTP/2 16
1.9 Parts of a web app 16
Handler 16
■
Template engine 17
1.10 Hello Go 18
1.11 Summary 21
2
Go ChitChat 22
2.1 Let’s ChitChat 23
2.2 Application design 24
2.3 Data model 26
2.4 Receiving and processing requests 27
The multiplexer 27
■ Serving static files
28
■ Creating the
handler function 28
■ Access control using cookies
30
2.5 Generating HTML responses with templates 32
Tidying up 36
2.6 Installing PostgreSQL 37
Linux/FreeBSD 37
■
Mac OS X 38
■
Windows 38
2.7 Interfacing with the database 38
2.8 Starting the server 43
2.9 Wrapping up 43
2.10 Summary 44
P ART 2 B ASIC WEB APPLICATIONS ............................... 45
3
Handling requests 47
3.1 The Go net/http library 48
3.2 Serving Go 50
The Go web server 50
■
Serving through HTTPS 51
3.3 Handlers and handler functions 55
Handling requests 55
■
More handlers 56
■
Handler
functions 57
■
Chaining handlers and handler functions 59
ServeMux and DefaultServeMux 63
■
Other multiplexers 64
CONTENTS ix
3.4 Using HTTP/2 66
3.5 Summary 68
4
Processing requests 69
4.1 Requests and responses 69
Request 70
■
Request URL 70
■
Request header 71
Request body 73
4.2 HTML forms and Go 74
Form 75
■
PostForm 77
■
MultipartForm 78
■
Files 80
Processing POST requests with JSON body 81
4.3 ResponseWriter 82
Writing to the ResponseWriter 83
4.4 Cookies 87
Cookies with Go 87
■
Sending cookies to the
browser 88
■
Getting cookies from the browser 90
■
Using
cookies for flash messages 92
4.5 Summary 95
5
Displaying content 96
5.1 Templates and template engines 97
5.2 The Go template engine 98
Parsing templates 100
■
Executing templates 101
5.3 Actions 102
Conditional actions 102
■
Iterator actions 104
Set actions 105
■
Include actions 107
5.4 Arguments, variables, and pipelines 110
5.5 Functions 111
5.6 Context awareness 113
Defending against XSS attacks 116
■
Unescaping
HTML 118
5.7 Nesting templates 119
5.8 Using the block action to define default templates 123
5.9 Summary 124
6
Storing data 125
6.1 In-memory storage 126
CONTENTS x
6.2 File storage 128
Reading and writing CSV files 130
■
The gob package 132
6.3 Go and SQL 134
Setting up the database 134
■
Connecting to the
database 137
■
Creating a post 138
■
Retrieving a
post 140
■
Updating a post 141
■
Deleting a post 141
Getting all posts 142
6.4 Go and SQL relationships 143
Setting up the databases 143
■
One-to-many relationship 145
6.5 Go relational mappers 147
Sqlx 148
■
Gorm 149
6.6 Summary 152
P ART 3 B EING REAL ................................................. 153
7
Go web services 155
7.1 Introducing web services 155 7.2
Introducing SOAP-based web services 157
7.3 Introducing REST-based web services 160
Convert action to a resource 162 ■ Make the action a property
of the resource 163
7.4 Parsing and creating XML with Go 163
Parsing XML 163
■
Creating XML 171
7.5 Parsing and creating JSON with Go 174
Parsing JSON 175
■
Creating JSON 178
7.6 Creating Go web services 181
7.7 Summary 188
8
Testing your application 190
8.1 Go and testing 191
8.2 Unit testing with Go 191
Skipping test cases 195
■
Running tests in parallel 196
Benchmarking 197
8.3 HTTP testing with Go 200
8.4 Test doubles and dependency injection 204
Dependency injection with Go 205
CONTENTS xi
8.5 Third-party Go testing libraries 210
Introducing the gocheck testing package 211
■
Introducing the
Ginkgo testing framework 216
8.6 Summary 221
9
Leveraging Go concurrency 223
9.1 Concurrency isn’t parallelism 223
9.2 Goroutines 225
Using goroutines 225
■
Goroutines and performance 228
Waiting for goroutines 231
9.3 Channels 232
Synchronization with channels 233
■
Message passing with
channels 234
■
Buffered channels 235
■
Selecting
channels 237
9.4 Concurrency for web applications 240
Creating the photo mosaic 240
■
The photo mosaic web
application 243
■
Concurrent photo mosaic web
application 247
9.5 Summary 254
10
Deploying Go 256
10.1 Deploying to servers 257
10.2 Deploying to Heroku 263
10.3 Deploying to Google App Engine 266
10.4 Deploying to Docker 271
What is Docker? 271
■
Installing Docker 272
■
Docker
concepts and components 273
■
Dockerizing a Go web
application 274
■
Pushing your Docker container to the
internet 276
10.5 Comparison of deployment methods 279
10.6 Summary 280
appendix Installing and setting up Go 281
index 285
|