Golang
凭什么我芒果过敏
这个作者很懒,什么都没留下…
展开
-
Golang——包
go包原创 2023-02-01 17:52:40 · 241 阅读 · 0 评论 -
Golang——异常和error
异常原创 2023-01-12 15:17:37 · 564 阅读 · 0 评论 -
Golang——管道、groutine、同步
管道原创 2022-12-23 14:01:54 · 217 阅读 · 0 评论 -
Golang——锁
锁原创 2022-12-19 11:09:05 · 49 阅读 · 0 评论 -
golang——tag
tag原创 2022-11-16 11:36:17 · 60 阅读 · 0 评论 -
Golang——结构体
结构体原创 2021-06-15 16:28:27 · 118 阅读 · 0 评论 -
Golong——标准输入输出
1.输入:两个都得先声明1)fmt.Scanln(&len)2)fmt.Scanf("%s %d %f %t", &name, &age, &salary, &isOffer)2.输出1)fmt.Println(len)2)格式化打印,不自动换行fmt.Printf("%d",a)原创 2021-04-19 10:56:03 · 172 阅读 · 0 评论 -
Golong——省略号...
https://blog.csdn.net/qq_31930499/article/details/98353008原创 2021-04-08 20:28:02 · 84 阅读 · 0 评论 -
Golong——垃圾回收
1.make和new的区别详细见https://studygolang.com/articles/3496func new(Type) *Type:new的作用是返回一个指向类型的指针func make(Type, size IntegerType) Type :make 的作用是为 slice, map 或者 channel 初始化,并且返回这个类型2.栈中分配的变量,出栈的时候不会被释放吗? func newInt *int { var i int return原创 2021-03-23 09:04:40 · 95 阅读 · 0 评论 -
Golong——http
1.服务器:响应客户端的请求法1:package mainimport ( "log" "net/http")type server intfunc (h *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Println(r.URL.Path) w.Write([]byte("Hello World!"))}func main() { var s server http.ListenAndSe原创 2021-02-07 17:00:10 · 88 阅读 · 0 评论 -
Golong——首字母大小写
https://blog.csdn.net/skh2015java/article/details/54316195原创 2021-02-07 16:19:45 · 112 阅读 · 0 评论 -
Golong——panic、recover
https://ieevee.com/tech/2017/11/23/go-panic.html原创 2021-02-07 15:38:18 · 51 阅读 · 0 评论 -
Golang——类型断言
https://juejin.cn/post/6844904153056034823原创 2021-02-03 18:04:25 · 52 阅读 · 0 评论 -
Golang——语句
continue语句和break语句的区别:1、break:while循环break是用于zhi永久终止循环。即不dao执行本次循环中break后面的语句,直zhuan接shu跳出循环。2、continue:while循环continue是用于终止本次循环。即本次循环中continue后面的代码不执行,进行下一次循环的入口判断。...原创 2021-01-08 11:02:29 · 53 阅读 · 0 评论 -
Golang——匿名函数and闭包
匿名函数and闭包原创 2020-12-31 15:54:48 · 352 阅读 · 0 评论 -
Golang——defer
1.defer用于资源的释放2.https://tiancaiamao.gitbooks.io/go-internals/content/zh/03.4.html原创 2020-12-22 12:24:43 · 74 阅读 · 0 评论 -
Golang——传值 传引用
https://www.cnblogs.com/wang_yb/p/12126884.htmlleetcode:322Golang本质是传值1.对于普通类型(int, string 等等), 就是 传值 调用, 函数内对参数的修改, 不影响外面的变量2.对于 struct 指针, slice 和 map 类型, 函数内对参数的修改之所以能影响外面, 是因为参数和外面的变量指向了同一块数据的地址3.对于 struct 指针, slice 和 map 类型, 函数的参数和外面的变量的地址是不一样的,原创 2020-12-17 19:15:48 · 197 阅读 · 0 评论 -
Golang——堆
堆:数组实现的完全二叉树1.堆的接口定义:go默认是小顶堆type Interface interface { Len() int //sort.Interface Less(i, j int) bool Swap(i, j int) Push(x interface{}) Pop() interface{} }2.使用1)定义了一个类型,这个类型实现了堆的接口后,此类型就可使用heap包type IntHeap []intfunc (h IntHeap) Len()原创 2020-12-14 15:51:58 · 566 阅读 · 0 评论 -
Golang——踩坑(无法分类情况
1.for循环使用多个变量for expression1; expression2; expression3 { ...}// 错误写法: ++ --是语句而不是表达式//不能使用i++,j-- ,正解为:i = i + 1, j = j + 1func main() { sum := 0 for i, j := 1, 10; i < j; i++,j++ { sum += i + j } fmt.Println("sum is equal to ", sum)}/原创 2020-12-07 18:33:22 · 191 阅读 · 0 评论 -
Golang——接口
https://sanyuesha.com/2017/07/22/how-to-understand-go-interface/+Golang——string中的排序原创 2020-11-29 16:15:06 · 133 阅读 · 0 评论 -
Golang——type
package mainimport ( "fmt")type NewInt int // 将NewInt定义为int类型type IntAlias = int // 将int取一个别名叫IntAliasfunc main() { var a NewInt fmt.Printf("a type: %T\n", a) var a2 IntAlias fmt.Printf("a2 type: %T\n", a2)}运行结果:a 的类型是 main原创 2020-11-29 15:21:59 · 122 阅读 · 0 评论 -
Golang——标准库中
math.Sqrt(x float64) float64math.Min(x float64,y float64) float64b := 1 //inta := math.Sqrt(float64(b)) //只接收float64类型,故需进行类型转换if a > b //wrong,比较时类型必须一致if int(a) > b //right原创 2020-11-05 21:43:35 · 139 阅读 · 0 评论 -
Golang——返回多个值
func findmin(nums []int) (int,int) { .... return a,b}if value,ok := m[key]Q:为什么可以返回多个值呢?原创 2020-11-02 23:06:03 · 941 阅读 · 0 评论 -
Golang——切片
1.声明var a []int //=nil,len=cap=0,可进行append,当append时,发现底层数组容量不够,会2倍自动扩容2.初始化var a = []int{} //注意等号原创 2020-10-29 11:55:07 · 928 阅读 · 0 评论 -
Golang——变量声明
“:=” 只能在声明局部变量的时候使用“var” 没有限制,全局变量必须用var声明原创 2020-10-29 11:36:52 · 64 阅读 · 0 评论 -
Golang——string
string原创 2020-10-28 10:57:41 · 857 阅读 · 0 评论 -
Golang——uint32
leetcode:190、1911.uint(usigned)均是无符号整型,uint、uint64占用内存64位。2.int带符号整型,占64位题目其实给定的是十进制var num uint32 = 43261596,计算机内存以32位补码形式存储此数,题目说颠倒此数的二进制位,十进制变为2进制:除2取余。3.取10进制数据最低位:n%10,n=n/10;num := 9 // intfor ...{ ...}//会得到9、84.取(10进制的)2进制格式数据最低位:n%2,原创 2020-10-27 16:39:29 · 2341 阅读 · 0 评论 -
Golang——位运算
1.位运算都是在二进制的基础上进行运算的,所以在位运算之前要先将两个数转成二进制。2.进行位运算的两数,数据类型得一致num := 9fmt.Println(num&1)//1001 & 0001 = 0001leetcode:191原创 2020-10-27 15:42:34 · 377 阅读 · 0 评论 -
Golang——多重赋值
a, b = b, a//底层实现aTemp = abTemp = ba, b, a = bTemp, aTempleetcode:202原创 2020-10-26 17:09:55 · 413 阅读 · 0 评论 -
Golang——map
Golang——map初始化两种方法:m := map[int]bool{} //bool默认为falsem := make(map[int]bool) //map用make不需要加长度原创 2020-10-26 16:36:36 · 97 阅读 · 0 评论