-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
538 lines (381 loc) · 39.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>YC's Blog</title><meta name="author" content="Ycccccc"><meta name="copyright" content="Ycccccc"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="Anything Is Possible">
<meta property="og:type" content="website">
<meta property="og:title" content="YC's Blog">
<meta property="og:url" content="https://kqlxk.github.io/index.html">
<meta property="og:site_name" content="YC's Blog">
<meta property="og:description" content="Anything Is Possible">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://kqlxk.github.io/img/mmexport1714538039776.png">
<meta property="article:author" content="Ycccccc">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://kqlxk.github.io/img/mmexport1714538039776.png"><link rel="shortcut icon" href="/img/mmexport1714538039776.png"><link rel="canonical" href="https://kqlxk.github.io/index.html"><link rel="preconnect"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css?v=4.13.0"><link rel="stylesheet" href="/pluginsSrc/@fortawesome/fontawesome-free/css/all.min.css?v=6.5.1"><link rel="stylesheet" href="/pluginsSrc/@fancyapps/ui/dist/fancybox/fancybox.css?v=5.0.33" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
root: '/',
algolia: undefined,
localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容:${query}","hits_stats":"共找到 ${hits} 篇文章"}},
translate: undefined,
noticeOutdate: undefined,
highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
post: false
},
runtime: '',
dateSuffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: undefined,
lightbox: 'fancybox',
Snackbar: undefined,
infinitegrid: {
js: '/pluginsSrc/@egjs/infinitegrid/dist/infinitegrid.min.js?v=4.11.1',
buttonText: '加载更多'
},
isPhotoFigcaption: false,
islazyload: false,
isAnchor: false,
percent: {
toc: true,
rightside: false,
},
autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: 'YC\'s Blog',
isPost: false,
isHome: true,
isHighlightShrink: false,
isToc: false,
postUpdate: '2024-11-23 17:25:58'
}</script><script>(win=>{
win.saveToLocal = {
set: (key, value, ttl) => {
if (ttl === 0) return
const now = Date.now()
const expiry = now + ttl * 86400000
const item = {
value,
expiry
}
localStorage.setItem(key, JSON.stringify(item))
},
get: key => {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = Date.now()
if (now > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
Object.keys(attr).forEach(key => {
script.setAttribute(key, attr[key])
})
document.head.appendChild(script)
})
win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = url
if (id) link.id = id
link.onerror = reject
link.onload = link.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
link.onload = link.onreadystatechange = null
resolve()
}
document.head.appendChild(link)
})
win.activateDarkMode = () => {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
win.activateLightMode = () => {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const t = saveToLocal.get('theme')
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><meta name="generator" content="Hexo 7.2.0"><link href="https://cdn.bootcss.com/KaTeX/0.11.1/katex.min.css" rel="stylesheet" /></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/mmexport1714538039776.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">16</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-book"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/todo/"><i class="fa-fw fas fa-list-alt"></i><span> ToDo</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw fas fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('/img/mmexport1714538039776.png')"><nav id="nav"><span id="blog-info"><a href="/" title="YC's Blog"><span class="site-name">YC's Blog</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-book"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/todo/"><i class="fa-fw fas fa-list-alt"></i><span> ToDo</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw fas fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">YC's Blog</h1><div id="site_social_icons"><a class="social-icon" href="https://github.com/kqlxk" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="/[email protected]" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/23/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L10-Redis/" title="[第六届字节青训营]L10-Redis">[第六届字节青训营]L10-Redis</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-23T07:52:53.000Z" title="发表于 2024-11-23 15:52:53">2024-11-23</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">什么是Redis
为什么需要Redis
随着数据量的增加,从一台mysql演化到了集群,但是在一些很复杂的技术场景里,mysql还是无法支持,由于mysql要从磁盘中读取数据,为了让数据查询更快,可以把数据存到内存里,redis应运而生
读取时先从redis中读,如果没有再去mysql读,然后再回写到redis中
回写时mysql产生binlog记录数据变更,使用架构解析binlog在写到redis中
redis基本原理
redis将数据存在内存中,但是也可以做到持久化
增量数据保存到AOF文件,全量数据RDB文件,实现持久化
redis单线程处理所有操作命令
Redis应用案例
连续签到
string数据结构
alloc:内存大小
len :实际使用的内存
消息通知
List数据结构Quicklist
一个节点中会存储很多数据
计数
Hash数据结构 - dict
排行榜
zset数据结构 - zskiplist
redis里跳表不超过4层
限流
分布式锁
Redis使用注意事项
大Key,热Key
定义
危害
解决方法
...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/18/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L9-Go-%E6%A1%86%E6%9E%B6%E4%B8%89%E4%BB%B6%E5%A5%97%E8%AF%A6%E8%A7%A3-Web-RPC-ORM/" title="[第六届字节青训营]L9-Go 框架三件套详解(Web/RPC/ORM)">[第六届字节青训营]L9-Go 框架三件套详解(Web/RPC/ORM)</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-18T14:49:42.000Z" title="发表于 2024-11-18 22:49:42">2024-11-18</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">GORM的基本使用
定义 gorm model
1234type Product struct{ Code string Price uint}
为model定义表名
123func (p Product) TableName() string{ return "product"}
如果没有定义表名,默认用结构体名的蛇形负数作为表名
数据库连接
1234567func main(){ dsn := "username/password@tcp(127.0.0.1:3306)/dbname?cahrset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.config{}) if err != nil{ panic(err) }}
创建数据
1err := db.Cr ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/18/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L8-%E5%B8%A6%E4%BD%A0%E8%AE%A4%E8%AF%86%E5%AD%98%E5%82%A8&%E6%95%B0%E6%8D%AE%E5%BA%93/" title="[第六届字节青训营]L8-带你认识存储&数据库">[第六届字节青训营]L8-带你认识存储&数据库</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-18T04:17:45.000Z" title="发表于 2024-11-18 12:17:45">2024-11-18</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">经典案例
数据的产生
数据的流动
数据的持久化
潜在的问题
存储 & 数据库简介
存储系统
系统概览
系统特点
简单:业务逻辑
复杂:错误处理
存储器层级结构
越往上,容量越小,性能越好,越贵
数据怎么从应用到存储介质
RAID 技术
数据库
概览
关系:实体与实体之间的联系
DSL:领域专用语言(人说人话,狗说狗话)
关系型数据库特点
非关系型数据库特点
数据库 VS 经典存储
结构化数据管理
事务能力
复杂查询能力
数据库的使用方式
主流产品刨析
单机存储
概览
本地文件系统
key-value 存储
分布式存储
HDFS
Ceph
单机数据库
关系型数据库
非关系型数据库
分布式数据库
解决容量问题
解决弹性问题
解决性价比问题
More to Do
新技术演进
概览
SPDK
AI & Storage
高性能硬件
总结
</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/17/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L7-%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BARPC%E6%A1%86%E6%9E%B6/" title="[第六届字节青训营]L7-深入浅出RPC框架">[第六届字节青训营]L7-深入浅出RPC框架</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-17T06:24:44.000Z" title="发表于 2024-11-17 14:24:44">2024-11-17</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">基本概念
本地函数调用
123456789101112func main( ){ var a var b result := calculate(a,b) fmt.Println(result) return}func calculate(x,y int){ Z := X*y return z}
将a和 b 的值压栈
通过函数指针找到 calculate 函数,进入函数取出栈中的值 2 和 3,将其赋予 x和 y
计算 x*y,并将结果存在 z
将z的值压栈,然后从 calculate 返回
从栈中取出 z返回值,并赋值给 result
远程函数调用(RPC)
函数映射:确定要用哪个函数
数据转换成字节流:传输参数的方式
网络传输:如何保证网络高效稳定的传输
RPC概念模型
理论模型:
一次RPC的完整过程
RPC的好处
RPC的弊端
小结
本地函数调用和 RPC 调用的区别:函数映射、数据转成字节流、网络传输
RPC 的概念模型:User、User-Stub、RPC-Runtime、Server-Stub、Server
一次 P ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/12/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L6-%E5%B0%86%E6%88%91%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%BC%80%E6%94%BE%E7%BB%99%E7%94%A8%E6%88%B7/" title="[第六届字节青训营]L6-将我的服务开放给用户">[第六届字节青训营]L6-将我的服务开放给用户</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-12T07:55:42.000Z" title="发表于 2024-11-12 15:55:42">2024-11-12</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">接入问题引入
一个报文的生命周期
企业接入升级打怪之路
域名系统
Host管理
通过hosts文件将主机名映射到IP地址
随着 example 公司业务规模和员工数量的增长,使用该方式面临诸多问题:
流量和负载:用户规模指数级增长,文件大小越来越大,统一分发引起较大的网络流量和cpu负载
名称冲突:无法保证主机名称的唯一性,同名主机添加导致服务故障
时效性:分发靠人工上传,时效性太差
使用域名系统
由于Host管理的劣势,可以用域名系统替换hosts文件
具体有以下规则:
域名空间被组织成树形结构
域名空间通过划分zone的方式进行分层授权管理
全球公共域名空间仅对应一棵树
根域名服务器:查询起点
域名组成格式:[a-zA-Z0-9-],以点划分label
如图所示
通用顶级域名(gTLD):gov政府 .edu教育.com商业.mil军事.org非盈利组织
域名报文格式:
域名购买与配置迁移
如何开放外部用户访问
自建DNS服务器
问题背景
域名系统依然存在问题:
内网域名的解析也得出公网去获取,效率低下
外部用户看到内网 ip 地址,容易被 hacker 攻击 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/10/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L5-%E6%89%93%E5%BC%80%E6%8A%96%E9%9F%B3%E4%BC%9A%E5%8F%91%E7%94%9F%E4%BB%80%E4%B9%88/" title="[第六届字节青训营]L5-打开抖音会发生什么">[第六届字节青训营]L5-打开抖音会发生什么</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-10T12:14:55.000Z" title="发表于 2024-11-10 20:14:55">2024-11-10</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">刷抖音是怎么交互的
为了方便理解满分为网络接入和网络传输
网络接入
互联网
物理联通:
路由
路由发包原理:
同网段:配置网段即可默认添加静态路由。获取对端MAC直接发包。(这里的同网段个人理解为一个子网络内)
跨网段:配置网关路由。获取网关MAC地址发包给网关(gateway)
动态路由:BGP/OSPF等,路由表在动态变化
路由是网状的,不一定是对称的
ARP协议
作用:查找下一个发送目标的MAC地址(同网段情况下)
ARP协议会向子网络中所有计算机发送一个数据包,包括自己的IP地址和查询主机的IP地址,在对方MAC地址上填FF:FF:FF:FF:FF:FF,每台计算机对IP地址进行比较,如果相同就回复自己的MAC地址
有几点要注意:
逻辑同网段才能发送ARP
ARP请求广播,ARP响应单播
免费ARP:主动广播告知MAC地址
场景:新增加了一台服务器,这台服务器通过广播告诉其他服务器他的MAC地址
代理ARP:劫持ARP请求,发往另一个虚拟网络/伪造MAC地址
场景:A发送ARP请求来请求B的MAC地址,代理ARP在交换机上劫持了这个请求,让 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/09/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L4-HTTP%E6%A1%86%E6%9E%B6%E4%BF%AE%E7%82%BC%E4%B9%8B%E8%B7%AF/" title="第六届字节青训营]L4-HTTP框架修炼之路">第六届字节青训营]L4-HTTP框架修炼之路</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-09T06:18:34.000Z" title="发表于 2024-11-09 14:18:34">2024-11-09</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">再谈HTTP协议
本部分回顾http协议
什么是HTTP协议
HTTP:超文本传输协议(Hypertext Transfer Protocol),(超文本:不只有文本,还有图片,视频,音频)
为什么需要协议:
明确信息的边界(开始,结束)
能够携带什么信息(什么消息,消息类型)
协议里有什么
下面是一个示例:
请求报文:
1234567POST /sis HTTP/1.1Who: ALexContent-Type: text/plainHost: 127.0.0.1:8888Content-Length: 28Let's watch a movie together
响应报文:
12345678HTTP/1.1 200 0KServer: hertzDate:Thu, 21 Apr 2022 11:46:32 GMTContent-Type:text/plain;charset=utf-8Content-Length:2Upstream-Caught: 16505415929845800K
下图是结构
请求流程
不足
HTTP1:队头阻塞,传输效率低,明文传输不安全
...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/06/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L3-%E9%AB%98%E8%B4%A8%E9%87%8F%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98%E5%AE%9E%E8%B7%B5/" title="[第六届字节青训营]L3-高质量编程与性能调优实践">[第六届字节青训营]L3-高质量编程与性能调优实践</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-06T09:08:21.000Z" title="发表于 2024-11-06 17:08:21">2024-11-06</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">高质量编程
高质量编程简介
什么是高质量
——编写的代码能够达到正确可靠、简洁清晰的目标可称之为高质量代码
各种边界条件是否考虑完备
异常情况处理,稳定性保证
易读易维护
编程原则
实际应用场景千变万化,各种语言的特性和语法各不相同,但是高质量编程遵循的原则是相通的
简单性:
消除“多余的复杂性”,以简单清晰的逻辑编写代码
不理解的代码无法修复改进
可读性:
代码是写给人看的,而不是机器
编写可维护代码的第一步是确保代码可读
生产力:
团队整体工作效率非常重要
编码规范
如何编写高质量的 Go 代码
代码格式
注释
命名规范
控制流程
错误和异常处理
代码格式
推荐使用 gofmt 自动格式化代码
gofmt:
Go 语言官方提供的工具,能自动格式化 Go 语言代码为官方统一风格,常见IDE都支持方便的配置
gofmt:
也是 Go 语言官方提供的工具实际等于 gofmt 加上依赖包管理自动增删依赖的包引用、将依赖包按字母序排序并分类
注释
注释应该做的:
注释应该解释代码作用
注释应该解释代码如何做的
注释应该解释代码实现的原因
...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/04/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L2-Go%E8%AF%AD%E8%A8%80%E5%B7%A5%E7%A8%8B%E5%AE%9E%E8%B7%B5/" title="[第六届字节青训营]L2-Go语言工程实践">[第六届字节青训营]L2-Go语言工程实践</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-04T04:51:43.000Z" title="发表于 2024-11-04 12:51:43">2024-11-04</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">语言进阶
goroutine
如何使用
只需要在调用的函数或方法前加上go关键字
12345go func() //创建一个新的 goroutine 运行函数fgo func(){ // ...}() //匿名函数也支持使用go关键字创建 goroutine 去执行。
启动单个goroutine
1234567891011121314package mainimport "fmt"func hello() { fmt.Println("hello world")}func main() { for { go hello() fmt.Println("你好,世界") }}
会交替输出这两句话
而如果没有加入for循环,重新执行程序后会输出
12你好,世界hello world
为什么会先打印 你好,世界?因为程序创建一个goroutine执行函数是是要花费时间的,而此时main函数会继续执行下去,所以会先打印下面的那句 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2024/11/02/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L1-Go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95/" title="[第六届字节青训营]L1-Go语言基础语法">[第六届字节青训营]L1-Go语言基础语法</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-11-02T05:40:02.000Z" title="发表于 2024-11-02 13:40:02">2024-11-02</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E9%9D%92%E8%AE%AD%E8%90%A5/">青训营</a></span></div><div class="content">go语言优势
高性能高并发
语法简单,学习曲线平缓
丰富的标准库
完善的工具链
静态链接
快速编译
跨平台
垃圾回收
go语言入门
之前做过详细笔记([Go]基本语法 | YC’s Blog),不多做赘述,只记一下有点生疏的
错误处理
errors包
在返回值中加一个 err ,可以由 errors.New("...") 创建
12345678func findUser(users []user, name string) (v *user, err error) { for _, u := range users { if u.name == name { return &u, nil } } return nil, errors.New("Not Found")}
在调用这个函数后,要先判断err是否为空
123456789101112131415func main() { users := [ ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span><a class="page-number" href="/page/2/#content-inner">2</a><span class="space">…</span><a class="page-number" href="/page/5/#content-inner">5</a><a class="extend next" rel="next" href="/page/2/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/mmexport1714538039776.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Ycccccc</div><div class="author-info__description">Anything Is Possible</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">16</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/kqlxk" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="/[email protected]" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/11/23/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L10-Redis/" title="[第六届字节青训营]L10-Redis">[第六届字节青训营]L10-Redis</a><time datetime="2024-11-23T07:52:53.000Z" title="发表于 2024-11-23 15:52:53">2024-11-23</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/11/18/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L9-Go-%E6%A1%86%E6%9E%B6%E4%B8%89%E4%BB%B6%E5%A5%97%E8%AF%A6%E8%A7%A3-Web-RPC-ORM/" title="[第六届字节青训营]L9-Go 框架三件套详解(Web/RPC/ORM)">[第六届字节青训营]L9-Go 框架三件套详解(Web/RPC/ORM)</a><time datetime="2024-11-18T14:49:42.000Z" title="发表于 2024-11-18 22:49:42">2024-11-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/11/18/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L8-%E5%B8%A6%E4%BD%A0%E8%AE%A4%E8%AF%86%E5%AD%98%E5%82%A8&%E6%95%B0%E6%8D%AE%E5%BA%93/" title="[第六届字节青训营]L8-带你认识存储&数据库">[第六届字节青训营]L8-带你认识存储&数据库</a><time datetime="2024-11-18T04:17:45.000Z" title="发表于 2024-11-18 12:17:45">2024-11-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/11/17/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L7-%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BARPC%E6%A1%86%E6%9E%B6/" title="[第六届字节青训营]L7-深入浅出RPC框架">[第六届字节青训营]L7-深入浅出RPC框架</a><time datetime="2024-11-17T06:24:44.000Z" title="发表于 2024-11-17 14:24:44">2024-11-17</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/11/12/%E7%AC%AC%E5%85%AD%E5%B1%8A%E5%AD%97%E8%8A%82%E9%9D%92%E8%AE%AD%E8%90%A5-L6-%E5%B0%86%E6%88%91%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%BC%80%E6%94%BE%E7%BB%99%E7%94%A8%E6%88%B7/" title="[第六届字节青训营]L6-将我的服务开放给用户">[第六届字节青训营]L6-将我的服务开放给用户</a><time datetime="2024-11-12T07:55:42.000Z" title="发表于 2024-11-12 15:55:42">2024-11-12</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
<i class="fas fa-folder-open"></i>
<span>分类</span>
<a class="card-more-btn" href="/categories/" title="查看更多">
<i class="fas fa-angle-right"></i></a>
</div>
<ul class="card-category-list" id="aside-cat-list">
<li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/"><span class="card-category-list-name">Go</span><span class="card-category-list-count">9</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/Go%E5%9F%BA%E7%A1%80/"><span class="card-category-list-name">Go基础</span><span class="card-category-list-count">4</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/gin%E6%A1%86%E6%9E%B6/"><span class="card-category-list-name">gin框架</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/grpc/"><span class="card-category-list-name">grpc</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/web/"><span class="card-category-list-name">web</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Go/%E6%95%B0%E6%8D%AE%E5%BA%93/"><span class="card-category-list-name">数据库</span><span class="card-category-list-count">2</span></a></li></ul></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/JWT/"><span class="card-category-list-name">JWT</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Mysql/"><span class="card-category-list-name">Mysql</span><span class="card-category-list-count">7</span></a></li>
</ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/HTML/" style="font-size: 1.1em; color: #999">HTML</a> <a href="/tags/gin%E6%A1%86%E6%9E%B6/" style="font-size: 1.1em; color: #999">gin框架</a> <a href="/tags/c/" style="font-size: 1.26em; color: #999fa8">c++</a> <a href="/tags/%E9%9D%92%E8%AE%AD%E8%90%A5/" style="font-size: 1.5em; color: #99a9bf">青训营</a> <a href="/tags/JWT/" style="font-size: 1.1em; color: #999">JWT</a> <a href="/tags/JS/" style="font-size: 1.1em; color: #999">JS</a> <a href="/tags/Go/" style="font-size: 1.42em; color: #99a6b7">Go</a> <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/" style="font-size: 1.1em; color: #999">计算机网络</a> <a href="/tags/grpc/" style="font-size: 1.1em; color: #999">grpc</a> <a href="/tags/GORM/" style="font-size: 1.1em; color: #999">GORM</a> <a href="/tags/git/" style="font-size: 1.1em; color: #999">git</a> <a href="/tags/Mysql/" style="font-size: 1.34em; color: #99a3b0">Mysql</a> <a href="/tags/css/" style="font-size: 1.1em; color: #999">css</a> <a href="/tags/%E4%BB%A3%E7%A0%81%E9%9A%8F%E6%83%B3%E5%BD%95/" style="font-size: 1.1em; color: #999">代码随想录</a> <a href="/tags/%E7%AC%AC%E4%B8%80%E7%AF%87%E5%8D%9A%E5%AE%A2/" style="font-size: 1.1em; color: #999">第一篇博客</a> <a href="/tags/%E5%89%8D%E7%AB%AF/" style="font-size: 1.18em; color: #999ca1">前端</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/11/"><span class="card-archive-list-date">十一月 2024</span><span class="card-archive-list-count">10</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/10/"><span class="card-archive-list-date">十月 2024</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/09/"><span class="card-archive-list-date">九月 2024</span><span class="card-archive-list-count">9</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/08/"><span class="card-archive-list-date">八月 2024</span><span class="card-archive-list-count">6</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/07/"><span class="card-archive-list-date">七月 2024</span><span class="card-archive-list-count">6</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/06/"><span class="card-archive-list-date">六月 2024</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/05/"><span class="card-archive-list-date">五月 2024</span><span class="card-archive-list-count">5</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">41</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2024-11-23T09:25:58.658Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/mmexport1714538039776.png')"><div id="footer-wrap"><div class="copyright">©2020 - 2024 By Ycccccc</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js?v=4.13.0"></script><script src="/js/main.js?v=4.13.0"></script><script src="/pluginsSrc/@fancyapps/ui/dist/fancybox/fancybox.umd.js?v=5.0.33"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js?v=4.13.0"></script></div></div></body></html>