This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://time.geekbang.org/column/article/126504 | |
// 张大爷在胡同口等着 ... | |
// 碰见一个李大爷:127.0.0.1:59668 | |
// 耗时: 40.354851ms | |
package main | |
import ( | |
"bytes" | |
"encoding/binary" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**KISS**原则是英语 Keep It Simple, Stupid 的首字母缩略字,是一种归纳过的经验原则。KISS 原则是指在设计当中应当注重简约的原则 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**SOLID**指代了面向对象编程、面向对象设计时的五个基本原则: | |
- 单一功能原则(S): 认为对象应该仅具有一种单一功能的概念 | |
- 开闭原则(O): 认为软件体应该是对于扩展开放的,但是对于修改封闭的”的概念 | |
- 里氏替换原则(L): 认为程序中的对象应该是可以在不改变程序正确性的前提下被它的子类所替换的概念 | |
- 接口隔离原则(I): 认为多个特定客户端接口要好于一个宽泛用途的接口的概念 | |
- 依赖反转原则(D): 认为一个方法应该遵从“依赖于抽象而不是一个实例”的概念,依赖注入是该原则的一种实现方式 | |
当这些原则被一起应用时,它们使得一个程序员开发一个容易进行软件维护和扩展的系统变得更加可能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 安装 | |
```sh | |
brew install rabbitmq | |
``` | |
### 自带的WEB管理页面 | |
- url:http://localhost:15672 | |
- 默认用户名、密码:guest、guest | |
### 说明 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[参考](http://www.bootcss.com/p/git-guide/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Go标准库可以大致按其中库的功能进行以下粗略的分类 | |
- 输入输出: 这个分类包括二进制以及文本格式在屏幕、键盘、文件以及其他设备上的输入输出等,比如二进制文件的读写。对应于此分类的包有`bufio`、`fmt`、`io`、`log`和`flag`等,其中 `flag` 用于处理命令行参数。 | |
- 文本处理: 这个分类包括字符串和文本内容的处理,比如字符编码转换等。对应于此分类的包有`encoding`、 `bytes`、 `strings`、 `strconv`、 `text`、 `mime`、 `unicode`、 `regexp`、`index`和`path`等。其中`path`用于处理路径字符串。 | |
- 网络: 这个分类包括开发网络程序所需要的包,比如Socket编程和网站开发等。对应于此分类的包有:`net`、 `http`、`html`和`expvar`等。 | |
- 系统: 这个分类包含对系统功能的封装,比如对操作系统的交互以及原子性操作等。对应于此分类的包有`os`、`syscall`、`sync`、`time`、`context`和`unsafe`等。 | |
- 数据结构与算法: 对应于此分类的包有`math`、`sort`、 `container`、 `crypto`、 `hash`、`archive`、`compress`和`image`等。因为`image`包里提供的图像编解码都是算法,所以也归入此类。 | |
- 运行时: 对应于此分类的包有:`runtime`、 `reflect`和`go`等 | |
- 时间:时间处理,对应的是`time` | |
- 测试:测试相关,提供单元测试、基准测试等,有`testing` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 函数传递是传值还是传引用 | |
**Go中是没有引用传递的** | |
- 基础类型是对值拷贝传递 | |
- 引用类型是对指针拷贝传递 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### make和new的区别 | |
```go | |
// The new built-in function allocates memory. The first argument is a type, | |
// not a value, and the value returned is a pointer to a newly | |
// allocated zero value of that type. | |
func new(Type) *Type | |
``` | |
- `new`只接受一个参数,这个参数是一个类型,分配好内存后,返回一个指向该类型内存地址的指针。同时请注意它同时把分配的内存置为零,也就是类型的零值 | |
```go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Goroutine | |
一个程序运行的时候 | |
- 一个进程 --> 多个线程 | |
- 一个逻辑处理器(默认和当前电脑CPU数目一致)`(P)` --> 多个线程 | |
- 一个线程`(M)`--> 多个协程 | |
- 调度器:go运行时中的,分配goroutine给不同的逻辑处理器,等待线程处理 | |
- 协程由go运行时实现 | |
- 全局运行队列:所有刚创建的goroutine都会放到这里 | |
- 本地运行队列:逻辑处理器的goroutine队列`(G)`,不超过256个 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Map | |
- map是基于散列表来实现,就是我们常说的Hash表 | |
- map存储的是无序的键值对集合 | |
- map的key,可以重复,如果重复了,则相当于覆盖,后面覆盖前者 | |
- map中的key可以是很多种类型,比如bool、数字、string、指针等,但是含有切片或函数的复杂类型则不能作为键使用,因为这几个没法用 == 来判断 | |
- 对于map的值来说,就没有什么限制了,切片这种在键里不能用的,完全可以用在值里 | |
```go | |
func main() { | |
var m map[int]string |
NewerOlder