上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 22 下一页
摘要: 将crt文件和server_no_passwd.key这两个文件拷贝到服务端的keys文件夹中 来自为知笔记(Wiz) 阅读全文
posted @ 2019-12-19 21:15 离地最远的星 阅读(226) 评论(0) 推荐(0) 编辑
摘要: models.proto syntax = "proto3"; package services; import "google/protobuf/timestamp.proto"; //引入timestamp的proto文件 //商品模型 message ProdModel { int32 pro 阅读全文
posted @ 2019-12-19 21:11 离地最远的星 阅读(535) 评论(0) 推荐(0) 编辑
摘要: 等待一组协程结束,用sync.WaitGroup操作 package main import ( "fmt" "sync" "time" ) func main() { wg := sync.WaitGroup{} for i := 0; i < 10; i++ { wg.Add(1) go calc(&wg, i) } wg... 阅读全文
posted @ 2019-12-19 20:59 离地最远的星 阅读(337) 评论(0) 推荐(0) 编辑
摘要: Go语言之unsafe包介绍及使用 unsafe内容介绍 type ArbitraryType int type Pointer *ArbitraryType func Sizeof(x ArbitraryType) uintptr func Offsetof(x ArbitraryType) uintptr func Alignof(x ArbitraryType) uintptr uns... 阅读全文
posted @ 2019-12-19 20:57 离地最远的星 阅读(622) 评论(0) 推荐(0) 编辑
摘要: server package main import ( "fmt" "net" ) func main() { listener, err := net.ListenUDP("udp", &net.UDPAddr{ IP: net.IPv4(0, 0, 0, 0), Port: 30000, }) if err !... 阅读全文
posted @ 2019-12-19 20:56 离地最远的星 阅读(276) 评论(0) 推荐(0) 编辑
摘要: server package main import ( "fmt" "net" ) //单独处理连接的函数 func process(conn net.Conn) { var buf = make([]byte, 1024) n, err := conn.Read(buf) // 返回读取到的字节数和错误信息 if err != nil { ... 阅读全文
posted @ 2019-12-19 20:54 离地最远的星 阅读(290) 评论(0) 推荐(0) 编辑
摘要: struct和byte类型转换 import ( "fmt" "unsafe" ) type TestStructTobytes struct { data int64 } type SliceMock struct { addr uintptr len int cap int } func main() { var testStruct = &TestStruc... 阅读全文
posted @ 2019-12-19 20:53 离地最远的星 阅读(2045) 评论(0) 推荐(0) 编辑
摘要: type T struct { f string `one:"1" two:"2"blank:""` } func main() { t := reflect.TypeOf(T{}) f, _ := t.FieldByName("f") fmt.Println(f.Tag) // one:"1" two:"2"blank:"" v, ok := f.Tag.... 阅读全文
posted @ 2019-12-19 20:53 离地最远的星 阅读(258) 评论(0) 推荐(0) 编辑
摘要: package main import "fmt" func tryRecover() int { defer func() { r := recover() if err, ok := r.(error); ok { fmt.Println("Error occurred", err) } else { ... 阅读全文
posted @ 2019-12-19 20:51 离地最远的星 阅读(281) 评论(0) 推荐(0) 编辑
摘要: panic的参数是一个空接口类型 interface{},所以任意类型的变量都可以传递给panic recover只有在defer后面的函数体里直接调用才能捕获panic终止异常,否则返回nil异常继续向外传递 defer recover() //这种写法捕捉失败 defer fmt.Println(recover()) //这种写法捕捉失败 defer func(){ func(){ ... 阅读全文
posted @ 2019-12-19 20:50 离地最远的星 阅读(1187) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 22 下一页