<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>坚持的事:读书&amp;攒钱</title>
    <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/</link>
    <description>Recent content on 坚持的事:读书&amp;攒钱</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    
	<atom:link href="https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>变量&amp;常量</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%8F%98%E9%87%8F%E5%B8%B8%E9%87%8F/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%8F%98%E9%87%8F%E5%B8%B8%E9%87%8F/</guid>
      <description>变量&amp;amp;常量 变量 1、显式的完整声明 var varName dataType [ = value] 说明: 关键字var用于变量声明 varName 是变量名称标识符 dataType 数据类型 value 初始化值 例子: var a int = 1 2、短类型声明 varName := value := 声明只能出现在函数内（包括在方法内） 此时Go编译器自动进行数据类型推断 a, b := 1, &amp;quot;hello&amp;quot;  常量 const a = 1 const ( a = iota ) </description>
    </item>
    
    <item>
      <title>defer</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/defer/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/defer/</guid>
      <description>defer 什么是defer  defer是Go语言的一种用于注册延迟调用的机制,使得函数或语句可以在当前函数执行完毕后执行.  为什么需要defer  Go语言提供的语法糖,减少资源泄露的发生.  如何使用defer  在创建资源语句的附近,使得defer语句释放资源.  例子 func f1() (r int) { t := 5 // 1. 赋值指令 r = t // 2. defer被插入到赋值与返回质检， 这个例子中返回值r没被修改过 defer func() { t = t + 5 }() // 3. 空的return指令 return t } 返回值是5 func f2() (r int) { defer func(r int) { r = r + 5 }(r) // 此处r是copy了一份 return 1 } 返回值是1 func f3() (r int) { defer func(r *int) { *r = *r + 5 }(&amp;amp;r) // 此处r是传址 return 1 } 返回值是6 defer 是先入先出 func e1() { var err error defer fmt.</description>
    </item>
    
    <item>
      <title>iota</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/iota/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/iota/</guid>
      <description>iota   const (
a = 1 &amp;laquo; iota // a==1 (iota == 0)
b = 1 &amp;laquo; iota // b==2 （iota == 1）
c = 3 // c == 3 (iota==2, unused)
d = 1 &amp;laquo; iota // d==8 (iota == 3) )
  const x = iota // x==0
  const y = iota // y==0 分开的const语句,iota每次都从0开始
  </description>
    </item>
    
    <item>
      <title>并行、并发与分布式计算</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%B9%B6%E8%A1%8C%E5%B9%B6%E5%8F%91%E4%B8%8E%E5%88%86%E5%B8%83%E5%BC%8F%E8%AE%A1%E7%AE%97/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%B9%B6%E8%A1%8C%E5%B9%B6%E5%8F%91%E4%B8%8E%E5%88%86%E5%B8%83%E5%BC%8F%E8%AE%A1%E7%AE%97/</guid>
      <description>ddd</description>
    </item>
    
    <item>
      <title>数据类型</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/</guid>
      <description>#数据类型
一、基本数据类型 Go 语言内置七类基本数据类型
1.布尔类型  True False //不初始化默认为false  2.整型 byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr  3.浮点型 float32 float64  4.复数 complex64 complex128 // real返回复数的实部, image返回复数的虚部  5.字符 rune //rune是uint类型的别名  6.字符串: string 赋值: a := &amp;quot;hello&amp;quot; a := &amp;quot;hello world&amp;quot; b := []byte(a) c := []rune(a) b和c的结果都是:[104 101 108 108 111 44 32 119 111 114 108 100]  7.错误类型: error 8.</description>
    </item>
    
    <item>
      <title>逃逸分析</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E9%80%83%E9%80%B8%E5%88%86%E6%9E%90/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E9%80%83%E9%80%B8%E5%88%86%E6%9E%90/</guid>
      <description>逃逸分析 例子 /* * 闭包引用了x变量, a,b可以看做2个不同的实例,实例之间互不影响,实例内部,x变量是同一个地址,因此具有&amp;quot;累加效应&amp;quot; */ package main import &amp;quot;fmt&amp;quot; func main() { var a = acc() fmt.Printf(&amp;quot;%d\n&amp;quot;, a(1)) fmt.Printf(&amp;quot;%d\n&amp;quot;, a(10)) fmt.Printf(&amp;quot;%d\n&amp;quot;, a(100)) fmt.Println(&amp;quot;-------------------&amp;quot;) var b = acc() fmt.Printf(&amp;quot;%d\n&amp;quot;, b(1)) fmt.Printf(&amp;quot;%d\n&amp;quot;, b(10)) fmt.Printf(&amp;quot;%d\n&amp;quot;, b(100)) } func acc() func(int) int { var x int return func(delta int) int { fmt.Printf(&amp;quot;%+v, %+v&amp;quot;, &amp;amp;x, x) x += delta return x } } 结果: 0xc000016070, 01 0xc000016070, 111 0xc000016070, 11111 ------------------- 0xc0000160b0, 01 0xc0000160b0, 111 0xc0000160b0, 11111 </description>
    </item>
    
    <item>
      <title>控制结构</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84/</guid>
      <description>控制结构 1.if语句 if err, file := os.Open(&amp;quot;xxx&amp;quot;); err == nil { //do smoething } else { return nil, err } if score &amp;gt;= 90 { } else if score &amp;gt;= 80 { } else { }  2.switch语句 switch 语句会根据传入的参数检测并执行符合条件的分支. switch 的语法特点如下: switch 和 if 语句一样, switch后面可以带一个可选的简单的初始化语句 switch 后面的表达式也是可选的, 如果没有表达式, 则case子句是一个布尔表达式. 而不是一个值, 此时就相当于多重if else语句 switch 条件表达式的值不像c语言那样必须限制为整数, 可以是任意支持相等比较运算的类型变量 通过fallthough语句来强制执行下一个case子句(不再判断下一个case子句的条件是否满足) switch支持default语句, 当所有的case分支都不符合时,执行default语句,并且default语句可以放到任意位置,并不影响switch的逻辑判断 swith和.(type)结合可以进行类型的查询， （//todo::） switch i := &amp;quot;y&amp;quot;; i { //switch后面可以带上一个初始化语句 case &amp;quot;y&amp;quot;, &amp;quot;Y&amp;quot;: //多个case值使用逗号分隔 fmt.</description>
    </item>
    
    <item>
      <title>函数</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%87%BD%E6%95%B0/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%87%BD%E6%95%B0/</guid>
      <description>函数  函数是一种类型,函数类型变量可以像其他类型变量一样使用,可以作为其他函数的参数或返回值,也可以直接调用执行。 函数支持多值返回 支持闭包 函数支持可变参数  基本概念 函数定义 func funcName(param-list) (result-list) { function-body }  函数的特点 1、函数可以没有输入, 也可以没有返回值(默认返回0) 2、多个相邻的相同类型的参数可以使用简写模式: func add(a, b int) int { //a int, b int 简写为 a,b int return a + b } 3、支持有名的返回值,参数名就相当于函数体内最外层的局部变量，命名返回值变量会被初始化为类型零值， 最后的return可以不带参数名直接返回 func add(a, b int) (sum int) { sum = a + b return //return sum的简写模式 // sum := a + b // 如果是 sum:=a + b, 则相当于新声明一个sum变量命名返回变量sum覆盖 // return sum //最后需要显示的调用return sum } 4、不支持默认值参数 5、不支持函数重载 6、不支持函数嵌套，严格地说是不支持命名函数的嵌套定义，但支持嵌套匿名函数 func add(a, b int) (sum int) { anonymouse := function(x, y int) int { return x + y } return anonymouse(a, b) }  多值返回 func swap(a, b int) (int, int) { return b, a }  实参到形参的传递 package main import &amp;quot;fmt&amp;quot; func chvalue(a int) int { a = a + 1 return a } func chpointer(a *int) { *a = *a + 1 return } func main() { a := 10 chvalue(a) //实参传递给形参是值拷贝 fmt.</description>
    </item>
    
    <item>
      <title>接口</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E6%8E%A5%E5%8F%A3/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E6%8E%A5%E5%8F%A3/</guid>
      <description>接口 语法 type Traversal interface { Traverse() }  duck typing 定义 使用者-&amp;gt;实现者
接口由使用者定义
接口的实现: 接口的实现是隐式的
只要实现接口里的方法
接口的值类型 fmt.printf(&amp;quot;%T, %v&amp;quot;, 接口变量, 接口变量) #打印接口类型和值 // r.(type) r的类型 switch v := r.(type) { case mock.Retriever: case *real.Retrieve: } // type assertion r.(*real.Retruever) 或 r, ok := r.(mock.Retruever) if ok != nil { fmt.Printf(&amp;quot;Err: %s&amp;quot;, ok) } 接口变量里面有什么: * 接口变量自带指针 * 接口变量同样采用值传递, 几乎不需要使用接口的指针 * 指针接收者实现只能以指针方式使用； 值接收者都可以  接口的组合 // 把Retriever和poster接口组合成一个接口 type RetrieverPoster interface { Retriever Poster }  常用接口 string reader writer  </description>
    </item>
    
    <item>
      <title>并发</title>
      <link>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%B9%B6%E5%8F%91/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://ruichengm1987.github.io/docs/go/%E5%9F%BA%E7%A1%80%E7%AF%87/%E5%B9%B6%E5%8F%91/</guid>
      <description>并发 进程、线程、协程   进程:
 进程是什么? 一种系统运行行动 进程的定位是什么? 程序的执行实体 进程长什么样子? 在terminal中查看 进程怎么使用? [一般情况]一个程序一个进程, [多进程]一个程序多个进程    线程:
 线程是什么? 运算调度的最小单元 线程的作用是什么? 同时运算多个任务 和进程有什么区别? 大哥和小弟的关系 线程内存大小?
怎么&amp;quot;切&amp;rdquo;? 内核控制
&amp;ldquo;切多大&amp;rdquo;? 缓存+内核控制
&amp;ldquo;等长吗&amp;rdquo;? 不等长 线程观摩  回到我们的terminal 输入命令ps -M [pid] 查看对应pid的线程      协程
 协程(Coroutine)是什么? 轻量级的线程 协程的定位是什么? 用户控制的函数 有什么样的优势? 协程优势  协程的内存消耗更小  一个线程可以包含多个协程 线程大约8MB的内存申请量 协程大概2kb的内存申请量   上下文切换更快  协程少一道手续 线程申请内存, 需要走过内核 协程申请内存，不需要走过内核        灵魂Goroutine</description>
    </item>
    
  </channel>
</rss>