03 2018 档案
摘要:5.7 安装 下载 https://downloads.mysql.com/archives/community/ 官网下载比较慢,国内镜像站可以加速下载,下载完成校验md5是否一致 http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/
阅读全文
摘要: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 type DB struct { mutex sync.Mutex store map[string][3]float64 } func (db DB) nearest(target [3]float64) string { var filename string db.mutex.
阅读全文
摘要:死锁 go package main import "fmt" func callerA(c chan string) { c
阅读全文
摘要:```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...
阅读全文
摘要:```go
package main import ( "log" "net" "net/rpc" "net/rpc/jsonrpc"
) type Args struct { A, B int
} type Result int type RpcServer struct{} func (t RpcServer) Add(args *Args, result *Result)...
阅读全文
摘要:```go package main import ( "crypto/tls" "fmt" "net/smtp"
) func main() { var email string fmt.Println("Enter username for smtp: ") fmt.Scanln(&email) var pass string fmt.Println("Enter p...
阅读全文
摘要:```go package main import ( "encoding/json" "fmt" "io" "io/ioutil" "net/http" "strconv" "strings" ) const addr = "localhost:7070" type City struct { I
阅读全文
摘要:```go package main import ( "fmt" "net/http"
) const addr = "localhost:7070" type RedirecServer struct { redirectCount int
} func (s *RedirecServer) ServeHTTP(rw http.ResponseWriter, req *htt...
阅读全文
摘要:```go package main import ( "fmt" "net/http"
) func main() { header := http.Header{} // Using the header as slice header.Set("Auth-X", "abcdef1234") header.Add("Auth-X", "defghijkl") fmt.P...
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.Parse...
阅读全文
摘要:```go
package main import ( "encoding/json" "fmt" "net/url"
) func main() { u := &url.URL{} u.Scheme = "http" u.Host = "localhost:80" u.Path = "index.html" u.RawQuery = "id=1&name=John" u....
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" "strings"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.Parse...
阅读全文
摘要:```go package main import ( "fmt" "net"
) func main() { // Resolve by IP addrs, err := net.LookupAddr("127.0.0.1") if err != nil { panic(err) } for _, addr := range addrs { fmt.Println...
阅读全文
摘要:```go package main import ( "bufio" "context" "fmt" "io" "net" "net/http" "time"
) type StringServer string func (s StringServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw....
阅读全文
摘要:```go package main import ( "fmt" "net"
) func main() { // Get all network interfaces interfaces, err := net.Interfaces() if err != nil { panic(err) } for _, interf := range interfaces ...
阅读全文
摘要:```go package main import ( "fmt" "log" "os/user"
) func main() { usr, err := user.Current() if err != nil { log.Fatal(err) } fmt.Println("The user home directory: " + usr.HomeDir)
} /*...
阅读全文
摘要:```go package main import ( "bufio" "crypto/md5" "fmt" "io" "os"
) var data = []struct { name string cont string perm os.FileMode
}{ {"test1.file", "Hello\nGolang is great", 0666}, {"test...
阅读全文
摘要:```go package main import ( "fmt" "os" "path/filepath" ) func main() { for i := 1; i
阅读全文
摘要:```go package main import ( "os"
) func main() { f, err := os.Create("created.file") if err != nil { panic(err) } f.Close() f, err = os.OpenFile("created.byopen", os.O_CREATE|os.O_APPEND,...
阅读全文
摘要:```go package main import ( "fmt" "os"
) func main() { f, err := os.Create("test.file") if err != nil { panic(err) } defer f.Close() // Obtain current permissions fi, err := f.Stat() ...
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "os" "path/filepath"
) func main() { fmt.Println("List by ReadDir") listDirByReadDir(".") fmt.Println() fmt.Println("List by Walk") listDirBy...
阅读全文
摘要:```go package main import ( "fmt" "io" "os" "sync"
) type SyncWriter struct { m sync.Mutex Writer io.Writer
} func (w *SyncWriter) Write(b []byte) (n int, err error) { w.m.Lock() defe...
阅读全文
摘要:```go package main import ( "io" "os" "strings"
) func main() { f, err := os.Create("sample.file") if err != nil { panic(err) } defer f.Close() _, err = f.WriteString("Go is awesome!\n...
阅读全文
摘要:```go package main import "io/ioutil"
import "os"
import "fmt" func main() { tFile, err := ioutil.TempFile("", "gostdcookbook") if err != nil { panic(err) } // The called is responsible for h...
阅读全文
摘要:```go package main import ( "fmt" "os"
) func main() { f, err := os.Open("test.file") if err != nil { panic(err) } fi, err := f.Stat() if err != nil { panic(err) } fmt.Printf("File n...
阅读全文
摘要:```go package main import ( "encoding/json" "fmt" "strings" ) const js = ` [{ "name":"Axel", "lastname":"Fooley" }, { "name":"Tim", "lastname":"Burton
阅读全文
摘要:```go package main import ( "archive/zip" "bytes" "fmt" "io" "io/ioutil" "log" "os"
) func main() { var buff bytes.Buffer // Compress content zipW := zip.NewWriter(&buff) f, err := zip...
阅读全文
摘要:```go package main import ( "bytes" "encoding/gob" "fmt" ) type User struct { FirstName string LastName string Age int Active bool } func (u User) Str
阅读全文
摘要:```go package main import ( "io" "log" "os" "os/exec"
) func main() { pReader, pWriter := io.Pipe() cmd := exec.Command("echo", "Hello Go!\nThis is example") cmd.Stdout = pWriter go func(...
阅读全文
摘要:```go
package main import "io"
import "bytes"
import "os"
import "fmt" func main() { buf := bytes.NewBuffer([]byte{}) f, err := os.OpenFile("sample.txt", os.O_CREATE|os.O_RDWR, os.ModePerm) if e...
阅读全文
摘要:```go package main import ( "bytes" "encoding/binary" "fmt"
) func main() { // Writing binary values buf := bytes.NewBuffer([]byte{}) if err := binary.Write(buf, binary.BigEndian, 1.004); er...
阅读全文
摘要:```go package main import ( "errors" "fmt" "os" ) const lineLegth = 25 func main() { f, e := os.OpenFile("flatfile.txt", os.O_RDWR|os.O_CREATE, os.ModePerm) if e != nil { panic(e) } defe...
阅读全文
摘要:```go package main import ( "fmt" "io/ioutil" "os" "golang.org/x/text/encoding/charmap"
) func main() { // Write the string // encoded to Windows-1252 encoder := charmap.Windows1252.NewEnc...
阅读全文
摘要:```go package main import "os"
import "bufio" import "bytes"
import "fmt"
import "io/ioutil" func main() { fmt.Println("### Read as reader ###") f, err := os.Open("temp/file.txt") if err != ni...
阅读全文
摘要:```go package main import ( "fmt" "io" "io/ioutil" "os"
) func main() { f, err := os.Open("temp/file.txt") if err != nil { panic(err) } c, err := ioutil.ReadAll(f) if err != nil { pa...
阅读全文
摘要:```go package main import ( "fmt" "io" "os" ) func main() { // Simply write string io.WriteString(os.Stdout, "This is string to standard output.\n") i
阅读全文
摘要:```go
package main import ( "fmt"
) func main() { var name string fmt.Println("What is your name?") fmt.Scanf("%s\n", &name) var age int fmt.Println("What is your age?") fmt.Scanf("%d\n", &...
阅读全文
摘要:```go package main import ( "encoding/json" "fmt" "time" ) func main() { eur, err := time.LoadLocation("Europe/Vienna") if err != nil { panic(err) } t
阅读全文
摘要:```go package main import ( "fmt" "time" ) func main() { to := time.After(3 time.Second) list := make([]string, 0) done := make(chan bool, 1) fmt.Prin
阅读全文
摘要:```go package main import ( "fmt" "sync" "time" ) func main() { t := time.NewTimer(3 time.Second) fmt.Printf("Start waiting at %v\n", time.Now().Forma
阅读全文
摘要:```go package main import ( "fmt" "os" "os/signal" "time" ) func main() { c := make(chan os.Signal, 1) signal.Notify(c) ticker := time.NewTicker(time.
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { eur, err := time.LoadLocation("Europe/Vienna") if err != nil { panic(err) } t := time.Date(2000, 1, 1, 0, 0, 0, 0, eur) fmt.Printf...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { l, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) } t := time.Date(2000, 1, 1, 0, 0, 0, 0, l) t2 := time.Da...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { l, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) } t := time.Date(2017, 11, 30, 11, 10, 20, 0, l) fmt.Print...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { t := time.Date(2017, 11, 29, 21, 0, 0, 0, time.Local) fmt.Printf("Extracting units from: %v\n", t) dOfMonth := t.Day() weekDay := t.W...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { // Set the epoch from int64 t := time.Unix(0, 0) fmt.Println(t) // Get the epoch // from Time instance epoch := t.Unix() fmt.Prin...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { // If timezone is not defined // than Parse function returns // the time in UTC timezone. t, err := time.Parse("2/1/2006", "31/7/2015...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { tTime := time.Date(2017, time.March, 5, 8, 5, 2, 0, time.Local) // The formatting is done // with use of reference value // Jan 2 15:...
阅读全文
摘要:```go package main import ( "fmt" "time"
) func main() { today := time.Now() fmt.Println(today) } /*
2018-03-22 00:18:44.558974 +0800 CST m=+0.000385597 */ ```
阅读全文
摘要:```go
package main import ( "crypto/md5" "fmt" "io" "os"
) var content = "This is content to check" func main() { checksum := MD5(content) checksum2 := FileMD5("content.dat") fmt.Printf("C...
阅读全文
摘要:```go package main import ( "fmt" "math/cmplx"
) func main() { // complex numbers are // defined as real and imaginary // part defined by float64 a := complex(2, 3) fmt.Printf("Real part: ...
阅读全文
摘要:```go package main import ( crypto "crypto/rand" "fmt" "math/big" "math/rand" ) func main() { sec1 := rand.New(rand.NewSource(10)) sec2 := rand.New(ra
阅读全文
摘要:```go package main import ( "fmt" "strconv"
) const bin = "10111"
const hex = "1A"
const oct = "12"
const dec = "10"
const floatNum = 16.123557 func main() { // Converts binary value into hex
...
阅读全文
摘要:```go
package main import ( "fmt"
) var integer int64 = 32500
var floatNum float64 = 22000.456 func main() { // Common way how to print the decimal // number fmt.Printf("%d \n", integer) // ...
阅读全文
摘要:```go package main import ( "fmt" "math" "math/big" ) const PI = const diameter = 3.0 const precision = 400 func main() { pi, _ := new(big.Float).SetP
阅读全文
摘要:```go
package main import ( "fmt" "math"
) var valA float64 = 3.55554444 func main() { // Bad assumption on rounding // the number by casting it to // integer. intVal := int(valA) fmt.Print...
阅读全文
摘要:```go package main import ( "fmt" "math" ) const da = 0.29999999999999998889776975374843459576368331909180 const db = 0.3 func main() { daStr := fmt.S
阅读全文
摘要:```go
package main import ( "fmt" "strconv"
) const bin = "00001"
const hex = "2f"
const intString = "12"
const floatString = "12.3" func main() { // Decimals res, err := strconv.Atoi(intStrin...
阅读全文
摘要:```go package main import ( "fmt" "strconv" "strings" "unicode"
) func main() { text := "Hi! Go is awesome." text = Indent(text, 6) fmt.Println(text) text = Unindent(text, 3) fmt.Println...
阅读全文
摘要:```go package main import ( "fmt" "math" "regexp" "strconv" "strings"
) func main() { stringToTrim := "\t\t\n Go \tis\t Awesome \t\t" trimResult := strings.TrimSpace(stringToTrim) fmt.Pr...
阅读全文
摘要:```go package main import ( "fmt" "strings" "unicode"
) const email = "ExamPle@domain.com"
const name = "isaac newton"
const upc = "upc"
const i = "i" const snakeCase = "first_name" func main(...
阅读全文
摘要:cat /Users/zrd/Downloads/gostandardlib/Chapter02/Strings\ and\ Things/recipe08/win1250.txt Gda�sk% decode
阅读全文
摘要:```go package main import ( "fmt" "regexp" ) const refString = `[{ \"email\": \"email@example.com\" \"phone\": 555467890}, { \"email\": \"other@domain
阅读全文
摘要:```go
package main import ( "fmt" "os" "text/tabwriter"
) func main() { w := tabwriter.NewWriter(os.Stdout, 15, 0, 1, ' ', tabwriter.AlignRight) fmt.Fprintln(w, "username\tfirstname\tlastname\...
阅读全文
摘要:性能测试 go package bench import ( "bytes" "testing" ) const testString = "test" func BenchmarkConcat(b testing.B) { var str string b.ResetTimer() for n :
阅读全文
摘要:##
```go
package main import ( "fmt" "strings"
) const selectBase = "SELECT * FROM user WHERE %s " var refStringSlice = []string{ " FIRST_NAME = 'Jack' ", " INSURANCE_NO = 333444555 ", " EFFEC...
阅读全文
摘要:遍历带空格的字符串 指定分割的字符串 去除特别符号 正则去掉特别字符串
阅读全文
摘要:```go
package main import ( "fmt" "strings"
) const refString = "Mary had a little lamb" func main() { lookFor := "lamb" contain := strings.Contains(refString, lookFor) fmt.Printf("The \"%s\"...
阅读全文
摘要:数据存储 存储在内存中 读写文件 CSV gob 二进制文件
阅读全文
摘要:模板引擎 无逻辑模板引擎, 嵌入逻辑模板引擎 简单的模板 goweb模板引擎需要两个步骤,1对文本的模板源进行语法分析,创建一个经过语法分析的模板结构,其中模板源可以是一个字符串,也可以是模板文件包含的内容;(2)经过执行语法分析的模板,将ResponseWriter和模板所需的动态数据传给模板引擎
阅读全文
摘要:Request 结构 组成: URL字段 Header字段 空行 Body字段 Form字段、postform字段,multipartForm字段 请求Url ·结构· URL格式一般为 request Header request Body Form POST FILE 方法2 response
阅读全文
摘要:config.json go package main import ( "encoding/json" "fmt" "os" ) type Client struct { consulIP string connString string } func (c Client) String() st
阅读全文
摘要:```go package main import ( "fmt" "io" "log" "os" "os/signal" "syscall" "time" ) var writer os.File func main() { // The file is opened as // a log fi
阅读全文
摘要:stdout 标准输入到标准输出
阅读全文
摘要:```go package main import ( "fmt" "os/exec" "runtime" "time" ) func main() { var cmd string if runtime.GOOS == "windows" { cmd = "timeout" } else { cmd = "sleep" } proc := exec.Comman...
阅读全文
摘要:```go package main import ( "fmt" "os" "os/signal" "syscall" ) func main() { // Create the channel where the received // signal would be sent. The Not
阅读全文
摘要:```go
package main import ( "fmt" "os" "os/exec" "strconv"
) func main() { pid := os.Getpid() fmt.Printf("Process PID: %d \n\n", pid) prc := exec.Command("ps", "-p", strconv.Itoa(pid), "-v"...
阅读全文
摘要:```go
package main import ( "fmt" "os" "path/filepath"
) func main() { ex, err := os.Executable() if err != nil { panic(err) } // Path to executable file fmt.Println("绝对路径: ", ex) // 绝对路径...
阅读全文
摘要:1 2 不存在则报错 3 设置获取删除环境变量
阅读全文
摘要:```go package main import ( "flag" "fmt" "log" "os" "strings" ) // Custom type need to implement // flag.Value interface to be able to // use it in fl
阅读全文
摘要:```go
package main import ( "fmt" "os"
) func main() { args := os.Args // all command line args println(args) // The first argument, zero item from array, // is the name of the called binar...
阅读全文
摘要:```go package main import ( "log" "runtime" ) const info = ` Application %s starting. The binary was build by GO: %s` func main() { log.Printf(info, "
阅读全文
摘要:Declare and access exported identifiers Pkg Declare and access exported identifiers Main Declare unexported identifiers and restrictions Pkg ( Declare
阅读全文
摘要:Return multiple values go // Sample program to show how functions can return multiple values while using // named and struct types. package main impor
阅读全文
摘要:method set go package main import "fmt" // Sample program to show how polymorphic behavior with interfaces. // 示例程序演示多态行为与接口的关系。 // reader is an inter
阅读全文
摘要:Declaring Fields Embedding types Embedded types and interfaces Outer and inner type interface implementations 外部和内部类型接口实现。 练习
阅读全文
摘要:Sharing data I Sharing data II Escape Analysis 溢出分析 练习
阅读全文
摘要:Declare, create and initialize struct types Anonymous struct types Named vs Unnamed types 命名类型和匿名类型 结构体类型排列
阅读全文
摘要:Declare, initialize and iterate Map literals and delete Map key restrictions key类型
阅读全文
摘要:Reference Types Taking slices of slices Appending slices go // Sample program to show how to grow a slice using the built in function append // and ho
阅读全文
摘要:... iota go // Sample program to show how iota works. package main import "fmt" func main() { const ( A1 = iota // 0 : Start at 0 B1 = iota // 1 : Inc
阅读全文
摘要:```go package main import "fmt" func main() { // Declare an array of five strings that is initialized // to its zero value. var strings [5]string stri
阅读全文

浙公网安备 33010602011771号