上一页 1 2 3 4 5 6 ··· 12 下一页

2018年3月27日

10.3 Running a code block only once 只运行一次代码块

摘要: go package main import ( "fmt" "sync" "time" ) var names = []interface{}{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo" 阅读全文

posted @ 2018-03-27 00:42 cucy_to 阅读(194) 评论(0) 推荐(0) 编辑

10.2 创建并发访问 Creating map for concurrent access

摘要: go package main import ( "fmt" "sync" ) var names = []string{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo"} func main( 阅读全文

posted @ 2018-03-27 00:37 cucy_to 阅读(123) 评论(0) 推荐(0) 编辑

10.1 Synchronizing 同步 access to a resource with Mutex

摘要: ```go package main import ( "fmt" "sync" ) var names = []string{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo"} type Sy 阅读全文

posted @ 2018-03-27 00:31 cucy_to 阅读(121) 评论(0) 推荐(0) 编辑

9.13 form

摘要: ```go package main import ( "fmt" "net/http" ) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { fmt.Printf("Prior ParseForm: %v\n", req.Form... 阅读全文

posted @ 2018-03-27 00:27 cucy_to 阅读(105) 评论(0) 推荐(0) 编辑

9.12 https

摘要: ```go Prepare the private key and self-signed X-509 certificate. For this purpose, the OpenSSL utility could be used. By executing the command openssl genrsa -out server.key 2048, the private key deri... 阅读全文

posted @ 2018-03-27 00:24 cucy_to 阅读(313) 评论(0) 推荐(0) 编辑

9.11 优雅的停止http服务

摘要: ```go package main import ( "context" "fmt" "log" "net/http" "os" "os/signal" "time" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/", fun 阅读全文

posted @ 2018-03-27 00:21 cucy_to 阅读(218) 评论(0) 推荐(0) 编辑

9.10 cookie

摘要: ```go package main import ( "fmt" "log" "net/http" "time" ) const cookieName = "X-Cookie" func main() { log.Println("Server is starting...") http.HandleFunc("/set", func(w http.ResponseWrite... 阅读全文

posted @ 2018-03-27 00:17 cucy_to 阅读(103) 评论(0) 推荐(0) 编辑

9.9 重定向

摘要: ```go package main import ( "fmt" "log" "net/http" ) func main() { log.Println("Server is starting...") http.Handle("/secured/handle", http.RedirectHa 阅读全文

posted @ 2018-03-27 00:14 cucy_to 阅读(153) 评论(0) 推荐(0) 编辑

9.8 模板文件

摘要: ```go ➜ recipe08 cat template.tpl Hi, I'm {{.}}! ``` ```go package main import "net/http" import "html/template" import "fmt" func main() { fmt.Println("Server is starting..."... 阅读全文

posted @ 2018-03-27 00:10 cucy_to 阅读(107) 评论(0) 推荐(0) 编辑

9.7 static file

摘要: ``` ➜ recipe07 tree . . ├── html │ └── page.html ├── static.go └── welcome.txt 1 directory, 3 files ``` ```go package main import ( "net/http" ) func main() { fileSrv := http.FileServer(htt... 阅读全文

posted @ 2018-03-27 00:08 cucy_to 阅读(100) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 12 下一页

导航