建立ssl/tls连接需要若干步骤,协议结合使用了对称加密和非对称加密,客户机和服务端需要协商所使用的算法并交换密钥信息.
下面以TLS 1.2为例介绍下流程(TlS1.3做了很多优化)
mysql group_concat数据过长截断
This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values
group_concat将非NULL的值拼接返回字符串,当没有非NULL的值时返回NULL.
有长度限制,遇到过一个由于长度限制数据截断导致的bug,sql如下
1 | -- 这里id,price都是int,4字节 |
这里将price拼接,再通过SUBSTRING_INDEX取最后一个price,由于数据截断,GROUP_CONCAT返回的字符串最后一个是”,”而不是price,导致SUBSTRING_INDEX取到的是””(字符串),在业务逻辑里直接转为int报错了,由此产生bug.
且只有当数据量足够多时才会触发(超过171行时,1024=1714+1702,引擎为InnnoDB,MySQL8.0,字符集为utf8mb4_0900_ai_ci)
1 | -- 有兴趣的可以复现下,查一个int类型的数据就行 |
go语言string按下标访问和for range访问有什么区别
下标访问
1 | func TestStr(t *testing.T) { |
range
1 | const nihongo = "日本語" |
Building Event-Driven Microservices
中文翻译:<微服务与事件驱动架构>
第一章
要点
- 康威定律
- 微服务
- 事件驱动架构
Concept
康威定律: 设计系统的组织……受到约束,产生的设计是这些组织的沟通结构的副本
Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations. - Melvin Conway(1967)
references:
阿里肥侠文章:”微服务架构的理论基础 - 康威定律” https://developer.aliyun.com/article/8611
康威定律详细介绍
1
2
3
4
5
6
7
8
9
10
11
12第一定律
Communication dictates design
组织沟通方式会通过系统设计表达出来
第二定律
There is never enough time to do something right, but there is always enough time to do it over
时间再多一件事情也不可能做的完美,但总有时间做完一件事情
第三定律
There is a homomorphism from the linear graph of a system to the linear graph of its design organization
线型系统和线型组织架构间有潜在的异质同态特性
第四定律
The structures of large systems tend to disintegrate during development, qualitatively more so than with small ystems
大的系统组织总是比小系统更倾向于分解
微服务
The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services , which may be written in different programming languages and use different data storage technologies.
– James Lewis and Martin FowlerMartin Fowler是国际著名的OO专家,敏捷开发方法的创始人之一,现为ThoughtWorks公司的首席科学家.福勒(Martin Fowler),在面向对象分析设计、UML、模式、软件开发方法学、XP、重构等方面,都是世界顶级的专家,现为Thought Works公司的首席科学家。Thought Works是一家从事企业应用开发和集成的公司。早在20世纪80年代,Fowler就是使用对象技术构建多层企业应用的倡导者,他著有几本经典书籍:《企业应用架构模式》、《UML精粹》和《重构》等。—— 百度百科
微服务问题
微服务架构需要考虑的问题,包括
- API Gateway
- 服务间调用
- 服务发现
- 服务容错
- 服务部署
- 数据调用
go-pprof
What
How
Display
- go tool pprof -http=:9999 cpu.pprof
Benchmark & pprof
gen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
func fib(n int) int {
if n == 0 || n == 1 {
return n
}
return fib(n-2) + fib(n-1)
}
func BenchmarkFib(b *testing.B) {
for n := 0; n < b.N; n++ {
fib(30) // run fib(30) b.N times
}
}
只需要在 go test 添加 -cpuprofile 参数即可生成 BenchmarkFib 对应的 CPU profile 文件:
$ go test -bench="Fib$" -cpuprofile=cpu.pprof .
goos: linux
goarch: amd64
pkg: example
BenchmarkFib-8 196 6071636 ns/op
PASS
ok example 2.046s
References
Go 正则匹配
正则匹配/regexp 规则
元字符
- ^ 匹配输入字符串的开始位置
- $ 匹配输入字符串的结束位置
example
vin码
1 | // 完整匹配: ^[A-HJ-NPR-Z\d]{8}[X\d][A-HJ-NPR-Z\d]{3}\d{5}$ |
references
nginx
Nginx
高性能的HTTP和反向代理服务器,Nginx 的主要功能:
- HTTP 服务器:Nginx 可以作为独立的 HTTP 服务器,提供静态和动态内容的托管。
- 反向代理:Nginx 可以作为反向代理服务器,将客户端请求转发到后端服务器,并将响应返回给客户端。
- 负载均衡:Nginx 支持多种负载均衡算法,如轮询、加权轮询和 IP 哈希,以实现请求的分发和服务器资源的优化利用。
- 邮件代理:Nginx 可以作为邮件代理服务器,支持 IMAP、POP3 和 SMTP 协议。
- 缓存:Nginx 支持 HTTP 缓存,可以缓存静态和动态内容,以提高性能和减少服务器负载。
- 安全性:Nginx 提供了多种安全功能,如访问控制、DDoS 保护和 SSL/TLS 加密。
配置
反向代理
每个站点在 conf.d目录下新增一个类似ssl.conf的配置文件,这样做的好处是将每个站点的配置单独放在一个文件,方便区分和修改.
1 | ls -al /etc/nginx/conf.d/ |
excel-usage
go-zeo usage
Go语言一千问解答
问题
- https://programnotes.cn/golang-1000-question/
- code,repo in github <git@github.com:yiGmMk/golang-1000-question.git>
- 代码允许环境:
- go version go1.15.3 linux/amd64
const
[001]iota,有常量如下,second数值是?
1
2
3
4
5
6const (
first = 1
second =iota
third
fourth
)- 答: 1
- 参考:
- go官方文档: https://golang.google.cn/pkg/builtin/#iota
- go by example: https://golangbyexample.com/iota-in-golang/
string
[002]strings.ReplaceAll,代码如下,replace的值是?
1
2
3
4origin := " 特斯拉Model X "
replace := strings.ReplaceAll(origin, " ", "")
fmt.Printf("origin:%s\nreplace:%s\n", origin, replace)答: “ 特斯拉Model X “,即origin