go rpc
摘要:server.go package mainimport ( "encoding/json" "fmt" "net" "net/rpc" "net/rpc/jsonrpc")type RpcTest struct {}type Result struct { Code int `json:"code
阅读全文
posted @
2022-10-10 21:15
paulversion
阅读(41)
推荐(0) 编辑
go 重试机制
摘要:package mainimport ( "fmt" "time")var RetryFlag chan bool = make(chan bool)func main() { Retry(test,[]int{3,5,10})}//重试次数func Retry(f func()bool,rules
阅读全文
posted @
2022-08-18 20:04
paulversion
阅读(58)
推荐(0) 编辑
go http编程
摘要:http的请求包包含 请求行,请求头,空行,请求体go的http编程 http server.go package main import "net/http" func main() { //注册处理函数,用户连接主动调用指定的函数 http.HandleFunc("/",handleFuncti
阅读全文
posted @
2019-10-03 09:17
paulversion
阅读(237)
推荐(0) 编辑
go实现多聊天并发 服务端
摘要:package mainimport ( "fmt" "net" "time")type Client struct { ch chan string //用户发送数据的管道 name string //用户名 addr string//网络地址} var message = make(chan s
阅读全文
posted @
2019-10-02 19:40
paulversion
阅读(428)
推荐(0) 编辑
go实现文件的上传
摘要:上传端 send.go package main import ( "fmt" "io" "net" "os") func main() { fmt.Println("请输入要传输的文件") var filePath string fmt.Scan(&filePath) info,err := os
阅读全文
posted @
2019-10-02 16:36
paulversion
阅读(4664)
推荐(0) 编辑
go socket 服务端处理多用户
摘要:package mainimport ( "fmt" "net" "strings")func main() { listener, err := net.Listen("tcp", "127.0.0.1:8000") if err != nil { fmt.Println(err.Error())
阅读全文
posted @
2019-10-02 15:00
paulversion
阅读(476)
推荐(0) 编辑
go socket
摘要:server.go package main package main import ( "fmt" "net") func main() { conn,err := net.Dial("tcp","127.0.0.1:8000") if err !=nil{ fmt.Println(err) }
阅读全文
posted @
2019-10-02 14:06
paulversion
阅读(221)
推荐(0) 编辑
go if for while 的使用
摘要:fileName := "a.txt"contents ,err := ioutil.ReadFile(fileName) if err != nil{ fmt.Println("文件不存在") }else{ fmt.Printf("%s\n",contents) } fileName := "a.
阅读全文
posted @
2019-09-23 08:53
paulversion
阅读(409)
推荐(0) 编辑
go常量的定义和枚举类型
摘要:const a,b int = 1,2 const a,b = 1,2 const ( a = "hello" b,c =3,4 ) 常量数值可作为各种类型使用 枚举类型的定义 普通枚举类型 const ( a = 1 b = 2 c = 3 ) 自增枚举类型 等价于 const( a = iota
阅读全文
posted @
2019-09-22 21:46
paulversion
阅读(1704)
推荐(0) 编辑
go语言的内建变量类型
摘要:string bool int int8 int16 int32 int64 uintptr 无符号int 类型 (u)int (u)int8 (u)int16 (u)int32 (u)int64 byte rune(字符类型) float32 float64 复数类型 complix64 comp
阅读全文
posted @
2019-09-22 21:31
paulversion
阅读(287)
推荐(0) 编辑
go 变量的定义方式
摘要:var a int a = 1 var a,b int a =1 b = 2 var a,b = 1,2 var s string = "hello world" a, b := 1,2 该变量类型的定义只能在函数内定义 var( aa = 3 s = "abc" b = true )
阅读全文
posted @
2019-09-22 21:07
paulversion
阅读(473)
推荐(0) 编辑