随笔分类 -  go

上一页 1 2 3 4 5 6 ··· 9 下一页
摘要:简单版 package main import ( "fmt" "io" "net/http" "os" "strconv" ) func HttpGet(url string) (result string, err error) { resp, err1 := http.Get(url) if 阅读全文
posted @ 2022-04-09 11:47 ty1539 阅读(62) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "strconv" ) func main() { // 把数字转换成字符串类型 i1 := int32(97) fmt.Printf("i1 = %d, %T, %#v,%#v \n",i1,i1,i1,string(i1)) ret2 := 阅读全文
posted @ 2022-04-09 10:52 ty1539 阅读(28) 评论(0) 推荐(0) 编辑
摘要:package main import ( "flag" "fmt" ) var ( recusive bool test string level int ) func init() { flag.BoolVar(&recusive,"r",false,"recusive xxx") flag.S 阅读全文
posted @ 2022-04-03 00:07 ty1539 阅读(153) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "os" ) func main(){ fmt.Println("args[0]=",os.Args[0] ) // os.Args[0] 是该程序的名称 if len(os.Args)>1 { for index,v := range os. 阅读全文
posted @ 2022-04-03 00:03 ty1539 阅读(679) 评论(0) 推荐(0) 编辑
摘要:读取文本 package main import ( "bufio" "fmt" "io" "os" ) // bufio是对文件读取file.Read(buf[:])的进一步封装,先从buf中读取,没有的话,再从文件读, func main(){ // 只读的方式打开 file,err := os 阅读全文
posted @ 2022-04-02 23:58 ty1539 阅读(132) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" ) type Animal interface { Talk() Eat() Name() string } type Dog struct { } func (d Dog) Talk() { fmt.Println("汪汪汪") } func 阅读全文
posted @ 2022-03-27 23:17 ty1539 阅读(107) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" ) func test(a interface{}) { // s := a.(int) // a.(int)接口转为int 如果不是这个类型,那就会panic,加入ok接收异常,就可以避免panic s, ok := a.(int) if o 阅读全文
posted @ 2022-03-27 19:12 ty1539 阅读(39) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "os" ) func main(){ var buf [67]byte // 定义一个66个字节的buf数组,输入你是个王八蛋死你祖宗十八代去掉你大爷的国相,多余2个字节 os.Stdin.Read(buf[:]) // 读取终端的输入放入到 阅读全文
posted @ 2022-03-27 18:42 ty1539 阅读(1399) 评论(0) 推荐(0) 编辑
摘要:tcp服务端 package main import ( "fmt" "net" "os" ) func errFunc(err error, info string) { if err != nil { fmt.Println("这是错误>>",info, err) //return //返回当前 阅读全文
posted @ 2022-03-27 16:05 ty1539 阅读(164) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "reflect" ) type Monster struct{ Name string `json: "name"` Age int `json: "monster_age"` Score float32 Sex string } //方法, 阅读全文
posted @ 2022-03-27 00:30 ty1539 阅读(25) 评论(0) 推荐(0) 编辑
摘要:常量常量介绍 常量使用const定义 常量在定义的时候,必须初始化 常量不能修改 常量只能修饰bool、数值类型(int,float系列)、string类型 语法:const identifier [type] = value 举例说明,看看下面的写法是否正确: const name = "tom" 阅读全文
posted @ 2022-03-26 22:52 ty1539 阅读(80) 评论(0) 推荐(0) 编辑
摘要:此处的变量reflect.TypeOf, reflect.ValueOf, 返回的 其实表示的不是真正的int,它是 reflect.TypeOf(b) 返回的type Type interface, 接口,里面包含了很多方法 不能 var a int = 10, var a1 rType=20 p 阅读全文
posted @ 2022-03-26 21:21 ty1539 阅读(32) 评论(0) 推荐(0) 编辑
摘要:#第17章反射 17.1先看一个问题,反射的使用场景 package main import ( "fmt" "encoding/json" ) type Monster struct { Name string `json: "monsterName"` Age int `json:"monste 阅读全文
posted @ 2022-03-26 13:27 ty1539 阅读(29) 评论(0) 推荐(0) 编辑
摘要:https://www.bookstack.cn/read/python-web-guide/2c13674c4e6a47cd.md 阅读全文
posted @ 2022-03-25 14:44 ty1539 阅读(31) 评论(0) 推荐(0) 编辑
摘要:https://blog.csdn.net/m0_37422289/article/details/105328796?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2 1. 简单并发 package main impor 阅读全文
posted @ 2022-03-21 00:22 ty1539 阅读(605) 评论(0) 推荐(0) 编辑
摘要:http.Get() https://golang.org/pkg/net/http/#Client package main import ( "fmt" "io/ioutil" "net/http" ) func main() { res, err := http.Get("https://ww 阅读全文
posted @ 2022-03-20 23:29 ty1539 阅读(75) 评论(0) 推荐(0) 编辑
摘要:package main import( "fmt" ) //声明|定义一个接口 type Usb interface{ //声明了两个没有实现的方法 start() stop() } type Phone struct {} //让phone 实现Usb接口的方法 func (p Phone) s 阅读全文
posted @ 2022-03-20 23:01 ty1539 阅读(29) 评论(0) 推荐(0) 编辑
摘要:不能,p2.Age 因为.的运算符高于, *p2.Age被cpu解析成p2的age值,再取值, 但是 * 只能对指针对象取值,正确做法: (*p2).Age 阅读全文
posted @ 2022-03-20 17:01 ty1539 阅读(16) 评论(0) 推荐(0) 编辑
摘要:ioutil.WriteFile package main import ( "fmt" "io/ioutil" ) func main(){ str := "hello world \n世界和平" err := ioutil.WriteFile("./test.txt",[]byte(str),0 阅读全文
posted @ 2022-03-20 15:55 ty1539 阅读(576) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "os" ) func main() { fmt.Println(" start ") //go run 要写全部路径, go build之后,用相对路径也是可以的 // file,err := os.OpenFile("./test.txt" 阅读全文
posted @ 2022-03-20 10:30 ty1539 阅读(221) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 9 下一页
点击右上角即可分享
微信分享提示