随笔分类 - 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:
阅读全文
摘要:go package main import ( "context" "fmt" "sync" "time" ) type SearchSrc struct { ID string Delay int } func (s SearchSrc) Search(ctx context.Context)
阅读全文
摘要:go package main import "sync" import "fmt" func main() { wg := sync.WaitGroup{} for i := 0; i
阅读全文
摘要:go package main import "sync" import "fmt" import "time" type Worker struct { id string } func (w Worker) String() string { return w.id } var globalCo
阅读全文
摘要:go package main import ( "fmt" "sync" "time" ) var names = []interface{}{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo"
阅读全文
摘要:go package main import ( "fmt" "sync" ) var names = []string{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo"} func main(
阅读全文
摘要:```go package main import ( "fmt" "sync" ) var names = []string{"Alan", "Joe", "Jack", "Ben", "Ellen", "Lisa", "Carl", "Steve", "Anton", "Yo"} type Sy
阅读全文
摘要:```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...
阅读全文
摘要:```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...
阅读全文
摘要:```go package main import ( "context" "fmt" "log" "net/http" "os" "os/signal" "time" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/", fun
阅读全文
摘要:```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...
阅读全文
摘要:```go package main import ( "fmt" "log" "net/http" ) func main() { log.Println("Server is starting...") http.Handle("/secured/handle", http.RedirectHa
阅读全文
摘要:```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..."...
阅读全文
摘要:```
➜ 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...
阅读全文
摘要:```go package main import ( "io" "log" "net/http" ) type User string func (u User) toString() string { return string(u) } type AuthHandler func(u User
阅读全文
摘要:```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 { ...
阅读全文
摘要:```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() {
...
阅读全文
摘要:```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......
阅读全文
摘要:```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)
...
阅读全文
摘要:```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...
阅读全文

浙公网安备 33010602011771号