-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
2,212 additions
and
614 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"go.formatTool": "goimports" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
docker run -d --hostname my-rabbit --name rmq -p 15672:15672 -p 5672:5672 -p 25672:25672 -e RABBITMQ_DEFAULT_USER=用户名 -e RABBITMQ_DEFAULT_PASS=密码 rabbitmq:3-management | ||
|
||
5672:连接生产者、消费者的端口。 | ||
15672:WEB管理页面的端口。 | ||
25672:分布式集群的端口。 | ||
|
||
Producer:生产者,负责生产消息。 | ||
Connect:连接,生产者与RMQ Server之间建立的TCP连接。 | ||
Channel:信道,一条连接可包含多条信道,不同信道之间通信互不干扰。考虑下多线程应用场景,每个线程对应一条信道,而不是对应一条连接,这样可以提高性能。 | ||
body:消息主体,要传递的数据。 | ||
exchange:交换器,负责把消息转发到对应的队列。交换器本身没有缓存消息的功能,消息是在队列中缓存的,如果队列不存在,则交换器会直接丢弃消息。常用的有四种类型的交换器:direct、fanout、topic、headers。不同类型的交换器有不同的交换规则,交换器会根据交换规则把消息转发到对应的队列。 | ||
exchangeName:交换器名称,每个交换器对应一个名称,发送消息时会附带交换器名称,根据交换器名称选择对应的交换器。 | ||
queue:队列,用于缓存消息。 | ||
BandingKey:绑定键,一个队列可以有一个到多个绑定键,通过绑定操作可以绑定交换器和队列,交换器会根据绑定键的名称找到对应的队列。 | ||
RotingKey:路由键,发送消息时,需要附带一条路由键,交换器会对路由键和绑定键进行匹配,如果匹配成功,则消息会转发到绑定键对应的队列中。 | ||
Consumer:消费者,负责处理消息。 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
172.20.0.1 | ||
docker network create -d bridge rabbitmq | ||
docker inspect 92 | ||
|
||
docker run -d --hostname rabbit-svr --name rabbit \ | ||
-p 5672:5672 -p 15672:15672 -p 25672:25672 \ | ||
-v /data/rabbitmq:/var/lib/rabbitmq rabbitmq:managment | ||
|
||
http://192.168.43.25: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
ssh-keygen -t rsa -C "[email protected]" // 三次回车即生成ssh-key,然后配置好 | ||
git config --list // 查看config | ||
git config --global user.name "wangchonglin" | ||
git config --global user.email [email protected] | ||
|
||
git config --global http.proxy 'socks5://127.0.0.1:1080' | ||
git config --global https.proxy 'socks5://127.0.0.1:1080' | ||
git config --global --unset http.proxy | ||
git config --global --unset https.proxy | ||
|
||
git init // 初始化本地版本库 | ||
git status // 查看本地版本库状态 | ||
git add . // 跟踪所有改动过的文件 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/ApesPlan/note | ||
|
||
go 1.12 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
go build -o 路径+文件.exe(输出) 路径+文件名(输入) | ||
// 编译到到指定文件 | ||
go build -o 路径+文件.exe(输出) 路径+文件名(输入) | ||
go build src/golang.org/x/tools/cmd/goimports // 编译并生成可执行文件到当前文件下 | ||
go install ... 编译并生成可执行文件到bin | ||
|
||
go get -v github.com/gpmgo/gopm // 下载编译好这个包,就可以不用翻墙下载go包 | ||
eg: gopm get g -v -u golang.org/x/tools/cmd/goimports | ||
|
||
值接收者是go语言特有 | ||
值/指针接收者均可接收值/指针,主要以接收者的形参为准 | ||
|
||
如何扩充系统类型或者别人的类型 | ||
定义别名 | ||
使用组合 | ||
// 值接收者是go语言特有 | ||
// 值/指针接收者均可接收值/指针,主要以接收者的形参为准 | ||
|
||
linux gopath | ||
~/go | ||
sdk 建议放在/opt | ||
在/etc/profile文件下添加三条语句 | ||
export GOROOT=/opt/go | ||
export PATH=$GOROOT/bin:$PATH | ||
export GOPATH=$HOME/goprojects/ | ||
// 如何扩充系统类型或者别人的类型 | ||
定义别名 | ||
使用组合 | ||
|
||
echo $GOPATH //打印gopath | ||
// linux 安装go | ||
// linux gopath | ||
~/go | ||
sdk 建议放在/opt | ||
在/etc/profile文件下添加三条语句 | ||
export GOROOT=/opt/go | ||
export PATH=$GOROOT/bin:$PATH | ||
export GOPATH=$HOME/goprojects/ | ||
|
||
不要通过共享内存来通信,要通过通信来共享内存 | ||
//打印gopath | ||
echo $GOPATH | ||
|
||
// 不要通过共享内存来通信,要通过通信来共享内存 | ||
|
||
// 切片常用操作 | ||
// 初始化 | ||
s := make([]int, 10, 32) | ||
// 复制 | ||
copy(s1, s2) // s2 覆盖 s1 中相同键的值[2,3,4,5,0,0,0,0,0] | ||
// 删除中间值 | ||
s := append(s[:3], s[4:]...) | ||
// pop | ||
front := s[0] | ||
s1 := s[1:] | ||
tail := s[len(s) - 1] | ||
s1 := s[:len(s) - 1] | ||
|
||
// map 常用操作 | ||
// 初始化 | ||
make(map[string]int) | ||
// 获取元素:m[key] | ||
// key不存在时,获取value类型的初始值 | ||
// 用value, ok := m[key]来判断是否存在key | ||
// 删除 | ||
delete(m, "name") | ||
|
||
map 的range不保证顺序变量,如需顺序需要手动对key排序 | ||
len获取元素个数 | ||
map使用的hash表,必须相同才相等 | ||
除了slice,map,function的内建类型都可以作为key | ||
Struct类型不包含上述字段,也可以作为key |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// 初始项目go mod,给项目生成go.mod | ||
go mod init XXX | ||
GO111MODULE on 开启gomod go get下载时也是下载到gopath/pkg/mod下 | ||
|
||
// GO111MODULE on 开启gomod go get下载时也是下载到gopath/pkg/mod下 | ||
默认值为auto,如果当前目录里有go.mod文件,就使用go modules,否则使用旧的GOPATH和vendor机制 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 将JSON数据解析成结构体 json.Unmarshal(xxx) | ||
// 将结构体解析成JSON数据 json.Marshal(xxx) | ||
|
||
// Marshal | ||
//与json数据对应的结构体 | ||
type Server struct { | ||
ServerName string `json:"serverName1"` | ||
ServerIP string `json:"serverIP2"` | ||
} | ||
// 数组对应slice | ||
type ServerSlice struct { | ||
Servers []Server `json:"servers3"` | ||
} | ||
|
||
func main() { | ||
var s ServerSlice | ||
s.Servers = append(s.Servers,Server{ServerName:"TianJin", ServerIP:"127.0.0.1"}) | ||
s.Servers = append(s.Servers,Server{ServerName:"BeiJing", ServerIP:"127.0.0.1"}) | ||
if data, err := json.Marshal(s); err == nil { | ||
fmt.Printf("%s\n", data) | ||
} | ||
} | ||
---output--- | ||
{"Servers":[{"ServerName":"TianJin","ServerIP":"127.0.0.1"}, {"ServerName":"BeiJing","ServerIP":"127.0.0.1"}]} | ||
|
||
// Unmarshal | ||
data:= `{"Servers":[{"ServerName":"TianJin","ServerIP":"127.0.0.1"}, {"ServerName":"BeiJing","ServerIP":"127.0.0.1"}]}` | ||
str:=[]byte(data) | ||
|
||
//1.Unmarshal的第一个参数是json字符串,第二个参数是接受json解析的数据结构。 | ||
//第二个参数必须是指针,否则无法接收解析的数据,如stu仍为空对象StuRead{} | ||
//2.可以直接stu:=new(StuRead),此时的stu自身就是指针 | ||
stuUnmarshal := ServerSlice{} | ||
err = json.Unmarshal(str,&stuUnmarshal) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
停止当前函数执行 | ||
一直向上返回,执行每一层的defer | ||
如果没有遇到recover,程序退出 | ||
// 停止当前函数执行 | ||
// 一直向上返回,执行每一层的defer | ||
// 如果没有遇到recover,程序退出 | ||
|
||
func main(){ | ||
defer_call() | ||
fmt.Println("333 Helloworld") | ||
} | ||
|
||
func defer_call() { | ||
defer func(){ | ||
fmt.Println("11111") | ||
}() | ||
defer func(){ | ||
fmt.Println("22222") | ||
}() | ||
|
||
defer func() { | ||
if r := recover(); r!= nil { | ||
fmt.Println("Recover from r : ",r) | ||
} | ||
}() | ||
|
||
defer func(){ | ||
fmt.Println("33333") | ||
}() | ||
|
||
fmt.Println("111 Helloworld") | ||
|
||
panic("Panic 1!") | ||
|
||
panic("Panic 2!") | ||
|
||
fmt.Println("222 Helloworld") | ||
} | ||
|
||
// 111 Helloworld | ||
// 33333 | ||
// Recover from r : Panic 1! | ||
// 22222 | ||
// 11111 | ||
// 333 Helloworld |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
content = strings.Replace(content, "\\u003c", "<", -1) | ||
content = strings.Replace(content, "\\u003e", ">", -1) | ||
content = strings.Replace(content, "\\u0026", "&", -1) | ||
// 如果路由中的&被转换成了\u0026 | ||
content = strings.Replace(content, "\\u003c", "<", -1) | ||
content = strings.Replace(content, "\\u003e", ">", -1) | ||
content = strings.Replace(content, "\\u0026", "&", -1) |
Oops, something went wrong.