随笔分类 -  golibs

摘要:go package main import ( "bufio" "context" "fmt" "log" "strings" "golang.org/x/sync/errgroup" ) const data = `line one line two with more words error: 阅读全文
posted @ 2018-03-27 01:06 cucy_to 阅读(224) 评论(0) 推荐(0)
摘要:go package main import ( "context" "fmt" "sync" "time" ) type SearchSrc struct { ID string Delay int } func (s SearchSrc) Search(ctx context.Context) 阅读全文
posted @ 2018-03-27 00:58 cucy_to 阅读(139) 评论(0) 推荐(0)
摘要:go package main import "sync" import "fmt" func main() { wg := sync.WaitGroup{} for i := 0; i 阅读全文
posted @ 2018-03-27 00:53 cucy_to 阅读(137) 评论(0) 推荐(0)
摘要:go package main import "sync" import "fmt" import "time" type Worker struct { id string } func (w Worker) String() string { return w.id } var globalCo 阅读全文
posted @ 2018-03-27 00:47 cucy_to 阅读(187) 评论(0) 推荐(0)
摘要: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 阅读(202) 评论(0) 推荐(0)
摘要: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 阅读(127) 评论(0) 推荐(0)
摘要:```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 阅读(124) 评论(0) 推荐(0)
摘要:```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 阅读(120) 评论(0) 推荐(0)
摘要:```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 阅读(331) 评论(0) 推荐(0)
摘要:```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 阅读(232) 评论(0) 推荐(0)
摘要:```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 阅读(109) 评论(0) 推荐(0)
摘要:```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 阅读(163) 评论(0) 推荐(0)
摘要:```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 阅读(114) 评论(0) 推荐(0)
摘要:``` ➜ 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 阅读(103) 评论(0) 推荐(0)
摘要:```go package main import ( "io" "log" "net/http" ) type User string func (u User) toString() string { return string(u) } type AuthHandler func(u User 阅读全文
posted @ 2018-03-26 23:52 cucy_to 阅读(188) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "net/http" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { ... 阅读全文
posted @ 2018-03-26 23:38 cucy_to 阅读(116) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "net/http" ) type SimpleHTTP struct{} func (s SimpleHTTP) ServeHTTP(rw http.ResponseWriter, r *http.Request) { fmt.Fprintln(rw, "Hello world") } func main() { ... 阅读全文
posted @ 2018-03-26 23:32 cucy_to 阅读(121) 评论(0) 推荐(0)
摘要:```go package main import ( "bufio" "fmt" "io" "net" ) func main() { l, err := net.Listen("tcp", ":8080") if err != nil { panic(err) } ID := 0 for { fmt.Println("Waiting for client...... 阅读全文
posted @ 2018-03-26 23:30 cucy_to 阅读(111) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "log" "net" ) func main() { pc, err := net.ListenPacket("udp", ":7070") if err != nil { log.Fatal(err) } defer pc.Close() buffer := make([]byte, 2048) ... 阅读全文
posted @ 2018-03-26 21:48 cucy_to 阅读(115) 评论(0) 推荐(0)
摘要:```go package main import ( "bufio" "fmt" "io" "net" ) func main() { l, err := net.Listen("tcp", ":8080") if err != nil { panic(err) } for { fmt.Println("Waiting for client...") conn... 阅读全文
posted @ 2018-03-24 00:06 cucy_to 阅读(110) 评论(0) 推荐(0)