Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day4 一致性哈希学习笔记 #71

Open
wants to merge 131 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
1393330
处理group嵌套问题
xutaoa Nov 30, 2019
0401256
add test func
xutaoa Nov 30, 2019
cd9bbe8
Merge pull request #4 from xutaoa/patch-2
geektutu Nov 30, 2019
0831e36
Merge pull request #3 from xutaoa/patch-1
geektutu Nov 30, 2019
4db622e
support group prefix nesting
geektutu Jan 8, 2020
64703ed
support group nesting
geektutu Jan 8, 2020
0c49220
add day7 doc
geektutu Jan 8, 2020
944309d
modify log
geektutu Jan 8, 2020
fcd8fae
fix gee-day7 title
geektutu Jan 9, 2020
bb58c2b
add go tutorial for gee
geektutu Jan 17, 2020
179e70e
move gee day1-day7 to gee-web
geektutu Jan 18, 2020
172d0cc
remove subdirectory gee from doc
geektutu Jan 18, 2020
ba48e16
add distributed cache day1 lru
geektutu Jan 19, 2020
4378b0d
add test func for lru
geektutu Jan 19, 2020
2b0d452
add go webassembly demo
geektutu Jan 23, 2020
6253d09
add group & sinks feature for geecache
geektutu Feb 2, 2020
3091a10
remove sinks
geektutu Feb 2, 2020
c822a1a
fix lru Value comments
geektutu Feb 2, 2020
cd12513
add geecache day1 & day2 to README
geektutu Feb 2, 2020
021ec73
day3 add http server for geecache
geektutu Feb 3, 2020
8ac52d7
day4 add consistent hash algorithm
geektutu Feb 3, 2020
3c18769
day5 multi node
geektutu Feb 3, 2020
8ac9c63
day5 multi nodes finish main func & add a auto start shell script
geektutu Feb 5, 2020
b3bf932
add English version's README
geektutu Feb 5, 2020
4b49356
day 6, support single flight
geektutu Feb 6, 2020
353ffe6
day7 support proto
geektutu Feb 6, 2020
e0f405b
update README.md, add day6 & day7 code link
geektutu Feb 6, 2020
15f1e5c
add gee-cache doc
geektutu Feb 7, 2020
1f47dbd
fix proto decode error
geektutu Feb 9, 2020
3b2e7ea
add geecache-day1 doc
geektutu Feb 11, 2020
75a5405
fix cache.go sync.Mutex, use Lock instead of RLock
geektutu Feb 11, 2020
2031e28
1. move cloneBytes from geecache.go to byteview.go 2. add more tests
geektutu Feb 12, 2020
3a92543
fix refer link format
geektutu Feb 13, 2020
d7a003f
fix lru dumplicate key, nbytes update issue
geektutu Feb 15, 2020
0be9d97
add day4/5 doc
geektutu Feb 16, 2020
30aad50
use go modules to replace relative path
geektutu Feb 20, 2020
78b6e80
add zhihu zhuanlan & weibo link
geektutu Feb 20, 2020
c5c650b
geeorm: a gorm-like orm framework
geektutu Feb 22, 2020
8db04dd
add day2 schema design
geektutu Feb 22, 2020
ba65123
Create LICENSE
geektutu Feb 23, 2020
d2c4089
mv session to single directory
geektutu Feb 23, 2020
95814ae
day3 add find multi records & find first record
geektutu Feb 23, 2020
66fdda8
refactor a better logger that supports different levels
geektutu Feb 24, 2020
cf3ae16
refactor Session, remove Value & lower SQL & SQLVars
geektutu Feb 24, 2020
01b2b4c
fix Drop table
geektutu Feb 25, 2020
80881c5
add day4 chain operation
geektutu Feb 25, 2020
394ea2e
remove geeorm directory
geektutu Feb 26, 2020
8ba70f2
add day5 update delete & count
geektutu Feb 26, 2020
53190e5
add day6 transaction
geektutu Feb 26, 2020
a5ca58d
clear session for every exec or query
geektutu Feb 26, 2020
09b6c3b
combine chain opertion & delete & update
geektutu Feb 28, 2020
dd3cedd
fix Insert Comment && add hooks feature
geektutu Feb 28, 2020
dd2f1d1
add day7 migrate
geektutu Feb 28, 2020
b7fdf41
add geeorm post url
geektutu Feb 29, 2020
7645de8
add geeorm day0 intro
geektutu Feb 29, 2020
a875e92
fix main.go addr define code
geektutu Mar 2, 2020
9e1174e
change the order of Header().Set() & WriteHeader()
geektutu Mar 3, 2020
e64de2e
init geeorm titles & description
geektutu Mar 3, 2020
3208237
add geeorm day1 & cmd_test
geektutu Mar 7, 2020
8b48181
add day2
geektutu Mar 7, 2020
9453b8b
add day3
geektutu Mar 7, 2020
2b03ff8
add day4-day7
geektutu Mar 8, 2020
b9f5de7
publish day3
geektutu Mar 8, 2020
eaf66a3
fix typo
geektutu Mar 14, 2020
d8451f9
Add custom table name
Mar 23, 2020
09764a0
fix tire to trie
geektutu Mar 29, 2020
bd6ec6c
init geebolt
geektutu Mar 29, 2020
7123e23
Remove redundant type conversion.
Mar 31, 2020
99821eb
Merge pull request #15 from singlemancombat/master
geektutu Apr 1, 2020
fb9b6cf
Return without info logging if failed to close database.
Apr 1, 2020
93f10c5
Merge pull request #16 from singlemancombat/master
geektutu Apr 1, 2020
d5509e0
fix geecache typo
geektutu Apr 20, 2020
2d18404
geerpc init project, add feature: decode & encode args, reply
geektutu May 3, 2020
9aae595
change top pos
geektutu May 16, 2020
190819a
Merge branch 'master' of https://github.com/geektutu/7days-golang
geektutu May 16, 2020
21f733b
change top pos
geektutu May 16, 2020
b4651d2
add codec & server code for gee-rpc
geektutu Sep 29, 2020
dfdb0ed
geerpc day2, implement a rpc client
geektutu Oct 1, 2020
0cc8314
fix HeaderPool recycle opportunity, add geerpc day3 service
geektutu Oct 1, 2020
7bd912d
remove headerPool to simplify the code
geektutu Oct 1, 2020
4f981d4
add geerpc day4 http and debug
geektutu Oct 1, 2020
714311d
remove duplicate error definition
geektutu Oct 2, 2020
a411eba
fix service numCalls read issue
geektutu Oct 2, 2020
d9162cc
gee-rpc: add Client struct filed opt to record options user will pass
geektutu Oct 2, 2020
7e7ee27
gee-rpc: implement day5-timeout
geektutu Oct 3, 2020
bc9eadf
gee-rpc day6 registry
geektutu Oct 4, 2020
7cd0399
gee-rpc day6 add discovery
geektutu Oct 4, 2020
366f09a
gee-rpc day6 add robin select for discovery
geektutu Oct 5, 2020
5a84e23
gee-rpc/day6: rename Robin to RoundRobin
geektutu Oct 5, 2020
7878979
gee-rpc/day7 add registry
geektutu Oct 5, 2020
c579748
README.md: add RPC Framework title for geerpc
geektutu Oct 5, 2020
b5c91b0
gee-web/day6 fix formatAsDate in go 1.15 issue #19
geektutu Oct 6, 2020
d52a027
gee-rpc/day7 use d.index to mode n to ensure safety
geektutu Oct 6, 2020
9a5edca
geerpc/day5 day6 day7: update the function description of XDial
geektutu Oct 6, 2020
03c85f7
gee-rpc add doc
geektutu Oct 6, 2020
298ce56
gee-rpc: gob.go use err = to replace err :=
geektutu Oct 6, 2020
6366346
gee-rpc client move call.Seq = seq to registerCall
geektutu Oct 7, 2020
1498ec2
gee-rpc: add day3 & day4 doc
geektutu Oct 7, 2020
28f1449
gee-rpc: if client is nil, close the connection
geektutu Oct 7, 2020
9f58ccc
gee-rpc/day4: add doc
geektutu Oct 7, 2020
e871cb3
gee-rpc: doc add day5 day6 day7
geektutu Oct 8, 2020
e8f6f7e
gee-rpc/doc fix day7 title
geektutu Oct 8, 2020
29b27e9
Merge pull request #12 from chaunceyjiang/tableName
geektutu Oct 12, 2020
fa60601
[ImgBot] Optimize images
ImgBotApp Oct 16, 2020
70fcb36
Merge pull request #20 from geektutu/imgbot
geektutu Oct 16, 2020
3024e8b
README.md: change the title apps to programs
geektutu Oct 18, 2020
9ddb657
README.md: add badges
geektutu Oct 18, 2020
c0e1f09
add 7days-golang questions
geektutu Oct 25, 2020
c79596f
modified geecache-day2 & add refer to 7days-golang Q & A
geektutu Oct 25, 2020
2f2be0c
support book for blog
geektutu Nov 3, 2020
d632550
geerpc/doc: fix github url
geektutu Nov 4, 2020
8e70671
method.Type.NumIn() => method.Type.NumOut()
geektutu Nov 22, 2020
658cc8a
remove hitcount, add high performance go
geektutu Nov 22, 2020
92a52ed
Update README.md
geektutu Nov 23, 2020
898e35e
fix goroutine loop variable reference issue
geektutu Dec 1, 2020
8ff3c45
add project url
geektutu Dec 6, 2020
3d0e400
rename geektutu-blog to blog
geektutu Jan 1, 2021
45e9992
Update geecache-day2.md
geektutu Jan 6, 2021
371cbe0
typo: geerpc-day1.md
imageslr May 25, 2021
9ef5cbb
Update geerpc-day1.md
imageslr May 25, 2021
cb2c370
Merge pull request #38 from imageslr/patch-1
geektutu May 26, 2021
59dacee
Merge pull request #37 from imageslr/master
geektutu May 26, 2021
4035589
Day4 一致性哈希学习笔记
Alcuin1 Jun 7, 2023
757bcdc
Update lru.go
Alcuin1 Jun 7, 2023
2bcb48d
Day2 单机并发缓存geecache.go
Alcuin1 Jun 8, 2023
4815d60
Day1 LRU 缓存淘汰策略 cache.go
Alcuin1 Jun 8, 2023
a5f414e
Day2 单机并发缓存 byteview.go
Alcuin1 Jun 8, 2023
fd3278e
Day2 单机并发缓存 geecache_test.go
Alcuin1 Jun 8, 2023
a668fe1
Day3 HTTP 服务端 http.go
Alcuin1 Jun 8, 2023
444d80f
Day3 HTTP 服务端 main.go
Alcuin1 Jun 8, 2023
3c0a793
Day5 分布式节点 peers.go
Alcuin1 Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.DS_Store
tmp
.idea
.vscode
tmp
*.db
*.sum
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Dai Jie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
364 changes: 145 additions & 219 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,219 +1,145 @@
# 7天用Go从零实现Web框架Gee

![Gee](doc/gee/gee.jpg)

Gee 的设计与实现参考了Gin,这个教程可以快速入门:[Go Gin简明教程](https://geektutu.com/post/quick-go-gin.html)。

## [教程目录](https://geektutu.com/post/gee.html)

- [第一天:前置知识(http.Handler接口)](https://geektutu.com/post/gee-day1.html),[Code - Github](day1-http-base)
- [第二天:上下文设计(Context)](https://geektutu.com/post/gee-day2.html),[Code - Github](day2-context)
- [第三天:Tire树路由(Router)](https://geektutu.com/post/gee-day3.html),[Code - Github](day3-router)
- [第四天:分组控制(Group)](https://geektutu.com/post/gee-day4.html),[Code - Github](day4-group)
- [第五天:中间件(Middleware)](https://geektutu.com/post/gee-day5.html),[Code - Github](day5-middleware)
- [第六天:HTML模板(Template)](https://geektutu.com/post/gee-day6.html),[Code - Github](day6-template)
- 第七天:错误恢复(Panic Recover),[Code - Github](day7-panic-recover)


## Day 1 - Static Route

```go
func main() {
r := gee.New()
r.GET("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "URL.Path = %q\n", req.URL.Path)
})

r.GET("/hello", func(w http.ResponseWriter, req *http.Request) {
for k, v := range req.Header {
fmt.Fprintf(w, "Header[%q] = %q\n", k, v)
}
})

r.Run(":9999")
}
```

## Day 2 - Context Design

```go
func main() {
r := gee.New()
r.GET("/", func(c *gee.Context) {
c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
})
r.GET("/hello", func(c *gee.Context) {
// expect /hello?name=geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Query("name"), c.Path)
})

r.POST("/login", func(c *gee.Context) {
c.JSON(http.StatusOK, &map[string]string{
"username": c.PostForm("username"),
"password": c.PostForm("password"),
})
})

r.Run(":9999")
}
```

## Day 3 - Dynamic Route

```go
func main() {
r := gee.New()
r.GET("/", func(c *gee.Context) {
c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
})

r.GET("/hello", func(c *gee.Context) {
// expect /hello?name=geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Query("name"), c.Path)
})

r.GET("/hello/:name", func(c *gee.Context) {
// expect /hello/geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Param("name"), c.Path)
})

r.GET("/assets/*filepath", func(c *gee.Context) {
c.JSON(http.StatusOK, gee.H{"filepath": c.Param("filepath")})
})

r.Run(":9999")
}
```

## Day 4 - Nesting Group Control

```go
func main() {
r := gee.New()
v1 := r.Group("/v1")
{
v1.GET("/", func(c *gee.Context) {
c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
})

v1.GET("/hello", func(c *gee.Context) {
// expect /hello?name=geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Query("name"), c.Path)
})
}
v2 := r.Group("/v2")
{
v2.GET("/hello/:name", func(c *gee.Context) {
// expect /hello/geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Param("name"), c.Path)
})
v2.POST("/login", func(c *gee.Context) {
c.JSON(http.StatusOK, &map[string]string{
"username": c.PostForm("username"),
"password": c.PostForm("password"),
})
})

}

r.Run(":9999")
}
```

## Day 5 - Middleware

```go
func onlyForV2() gee.HandlerFunc {
return func(c *gee.Context) {
// Start timer
t := time.Now()
// if a server error occurred
c.Fail(500, "Internal Server Error")
// Calculate resolution time
log.Printf("[%d] %s in %v for group v2", c.StatusCode, c.Req.RequestURI, time.Since(t))
}
}

func main() {
r := gee.New()
r.Use(gee.Logger()) // global midlleware
r.GET("/", func(c *gee.Context) {
c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
})

v2 := r.Group("/v2")
v2.Use(onlyForV2()) // v2 group middleware
{
v2.GET("/hello/:name", func(c *gee.Context) {
// expect /hello/geektutu
c.String(http.StatusOK, "hello %s, you're at %s\n", c.Param("name"), c.Path)
})
}

r.Run(":9999")
}
```

## Day 6 - HTML Template

```go
type student struct {
Name string
Age int8
}

func formatAsDate(t time.Time) string {
year, month, day := t.Date()
return fmt.Sprintf("%d-%02d-%02d", year, month, day)
}

func main() {
r := gee.New()
r.Use(gee.Logger())
r.SetFuncMap(template.FuncMap{
"formatAsDate": formatAsDate,
})
r.LoadHTMLGlob("templates/*")
r.Static("/assets", "./static")

stu1 := &student{Name: "Geektutu", Age: 20}
stu2 := &student{Name: "Jack", Age: 22}
r.GET("/", func(c *gee.Context) {
c.HTML(http.StatusOK, "css.tmpl", nil)
})
r.GET("/students", func(c *gee.Context) {
c.HTML(http.StatusOK, "arr.tmpl", gee.H{
"title": "gee",
"stuArr": [2]*student{stu1, stu2},
})
})

r.GET("/date", func(c *gee.Context) {
c.HTML(http.StatusOK, "custom_func.tmpl", gee.H{
"title": "gee",
"now": time.Date(2019, 8, 17, 0, 0, 0, 0, time.UTC),
})
})

r.Run(":9999")
}
```

## Day 7 - Panic Recover

```go
func main() {
r := gee.Default()
r.GET("/", func(c *gee.Context) {
c.String(http.StatusOK, "Hello Geektutu\n")
})
// index out of range for testing Recovery()
r.GET("/panic", func(c *gee.Context) {
names := []string{"geektutu"}
c.String(http.StatusOK, names[100])
})

r.Run(":9999")
}

```
# 7 days golang programs from scratch

[![CodeSize](https://img.shields.io/github/languages/code-size/geektutu/7days-golang)](https://github.com/geektutu/7days-golang)
[![LICENSE](https://img.shields.io/badge/license-MIT-green)](https://mit-license.org/)

<details>
<summary><strong>README 中文版本</strong></summary>
<div>

## 7天用Go从零实现系列

7天能写什么呢?类似 gin 的 web 框架?类似 groupcache 的分布式缓存?或者一个简单的 Python 解释器?希望这个仓库能给你答案。

推荐先阅读 **[Go 语言简明教程](https://geektutu.com/post/quick-golang.html)**,一篇文章了解Go的基本语法、并发编程,依赖管理等内容。

推荐 **[Go 语言笔试面试题](https://geektutu.com/post/qa-golang.html)**,加深对 Go 语言的理解。

推荐 **[Go 语言高性能编程](https://geektutu.com/post/high-performance-go.html)**([项目地址](https://github.com/geektutu/high-performance-go)),写出高性能的 Go 代码。

期待关注我的「[知乎专栏](https://zhuanlan.zhihu.com/geekgo)」和「[微博](http://weibo.com/geektutu)」,查看最近的文章和动态。

### 7天用Go从零实现Web框架 - Gee

[Gee](https://geektutu.com/post/gee.html) 是一个模仿 [gin](https://github.com/gin-gonic/gin) 实现的 Web 框架,[Go Gin简明教程](https://geektutu.com/post/quick-go-gin.html)可以快速入门。

- 第一天:[前置知识(http.Handler接口)](https://geektutu.com/post/gee-day1.html) | [Code](gee-web/day1-http-base)
- 第二天:[上下文设计(Context)](https://geektutu.com/post/gee-day2.html) | [Code](gee-web/day2-context)
- 第三天:[Trie树路由(Router)](https://geektutu.com/post/gee-day3.html) | [Code](gee-web/day3-router)
- 第四天:[分组控制(Group)](https://geektutu.com/post/gee-day4.html) | [Code](gee-web/day4-group)
- 第五天:[中间件(Middleware)](https://geektutu.com/post/gee-day5.html) | [Code](gee-web/day5-middleware)
- 第六天:[HTML模板(Template)](https://geektutu.com/post/gee-day6.html) | [Code](gee-web/day6-template)
- 第七天:[错误恢复(Panic Recover)](https://geektutu.com/post/gee-day7.html) | [Code](gee-web/day7-panic-recover)

### 7天用Go从零实现分布式缓存 GeeCache

[GeeCache](https://geektutu.com/post/geecache.html) 是一个模仿 [groupcache](https://github.com/golang/groupcache) 实现的分布式缓存系统

- 第一天:[LRU 缓存淘汰策略](https://geektutu.com/post/geecache-day1.html) | [Code](gee-cache/day1-lru)
- 第二天:[单机并发缓存](https://geektutu.com/post/geecache-day2.html) | [Code](gee-cache/day2-single-node)
- 第三天:[HTTP 服务端](https://geektutu.com/post/geecache-day3.html) | [Code](gee-cache/day3-http-server)
- 第四天:[一致性哈希(Hash)](https://geektutu.com/post/geecache-day4.html) | [Code](gee-cache/day4-consistent-hash)
- 第五天:[分布式节点](https://geektutu.com/post/geecache-day5.html) | [Code](gee-cache/day5-multi-nodes)
- 第六天:[防止缓存击穿](https://geektutu.com/post/geecache-day6.html) | [Code](gee-cache/day6-single-flight)
- 第七天:[使用 Protobuf 通信](https://geektutu.com/post/geecache-day7.html) | [Code](gee-cache/day7-proto-buf)

### 7天用Go从零实现ORM框架 GeeORM

[GeeORM](https://geektutu.com/post/geeorm.html) 是一个模仿 [gorm](https://github.com/jinzhu/gorm) 和 [xorm](https://github.com/go-xorm/xorm) 的 ORM 框架

gorm 准备推出完全重写的 v2 版本(目前还在开发中),相对 gorm-v1 来说,xorm 的设计更容易理解,所以 geeorm 接口设计上主要参考了 xorm,一些细节实现上参考了 gorm。

- 第一天:[database/sql 基础](https://geektutu.com/post/geeorm-day1.html) | [Code](gee-orm/day1-database-sql)
- 第二天:[对象表结构映射](https://geektutu.com/post/geeorm-day2.html) | [Code](gee-orm/day2-reflect-schema)
- 第三天:[记录新增和查询](https://geektutu.com/post/geeorm-day3.html) | [Code](gee-orm/day3-save-query)
- 第四天:[链式操作与更新删除](https://geektutu.com/post/geeorm-day4.html) | [Code](gee-orm/day4-chain-operation)
- 第五天:[实现钩子(Hooks)](https://geektutu.com/post/geeorm-day5.html) | [Code](gee-orm/day5-hooks)
- 第六天:[支持事务(Transaction)](https://geektutu.com/post/geeorm-day6.html) | [Code](gee-orm/day6-transaction)
- 第七天:[数据库迁移(Migrate)](https://geektutu.com/post/geeorm-day7.html) | [Code](gee-orm/day7-migrate)


### 7天用Go从零实现RPC框架 GeeRPC

[GeeRPC](https://geektutu.com/post/geerpc.html) 是一个基于 [net/rpc](https://github.com/golang/go/tree/master/src/net/rpc) 开发的 RPC 框架
GeeRPC 是基于 Go 语言标准库 `net/rpc` 实现的,添加了协议交换、服务注册与发现、负载均衡等功能,代码约 1k。

- 第一天 - [服务端与消息编码](https://geektutu.com/post/geerpc-day1.html) | [Code](gee-rpc/day1-codec)
- 第二天 - [支持并发与异步的客户端](https://geektutu.com/post/geerpc-day2.html) | [Code](gee-rpc/day2-client)
- 第三天 - [服务注册(service register)](https://geektutu.com/post/geerpc-day3.html) | [Code](gee-rpc/day3-service )
- 第四天 - [超时处理(timeout)](https://geektutu.com/post/geerpc-day4.html) | [Code](gee-rpc/day4-timeout )
- 第五天 - [支持HTTP协议](https://geektutu.com/post/geerpc-day5.html) | [Code](gee-rpc/day5-http-debug)
- 第六天 - [负载均衡(load balance)](https://geektutu.com/post/geerpc-day6.html) | [Code](gee-rpc/day6-load-balance)
- 第七天 - [服务发现与注册中心(registry)](https://geektutu.com/post/geerpc-day7.html) | [Code](gee-rpc/day7-registry)

### WebAssembly 使用示例

具体的实践过程记录在 [Go WebAssembly 简明教程](https://geektutu.com/post/quick-go-wasm.html)。

- 示例一:Hello World | [Code](demo-wasm/hello-world)
- 示例二:注册函数 | [Code](demo-wasm/register-functions)
- 示例三:操作 DOM | [Code](demo-wasm/manipulate-dom)
- 示例四:回调函数 | [Code](demo-wasm/callback)

</div>
</details>

What can be accomplished in 7 days? A gin-like web framework? A distributed cache like groupcache? Or a simple Python interpreter? Hope this repo can give you the answer.

## Web Framework - Gee

[Gee](https://geektutu.com/post/gee.html) is a [gin](https://github.com/gin-gonic/gin)-like framework

- Day 1 - http.Handler Interface Basic [Code](gee-web/day1-http-base)
- Day 2 - Design a Flexiable Context [Code](gee-web/day2-context)
- Day 3 - Router with Trie-Tree Algorithm [Code](gee-web/day3-router)
- Day 4 - Group Control [Code](gee-web/day4-group)
- Day 5 - Middleware Mechanism [Code](gee-web/day5-middleware)
- Day 6 - Embeded Template Support [Code](gee-web/day6-template)
- Day 7 - Panic Recover & Make it Robust [Code](gee-web/day7-panic-recover)

## Distributed Cache - GeeCache

[GeeCache](https://geektutu.com/post/geecache.html) is a [groupcache](https://github.com/golang/groupcache)-like distributed cache

- Day 1 - LRU (Least Recently Used) Caching Strategy [Code](gee-cache/day1-lru)
- Day 2 - Single Machine Concurrent Cache [Code](gee-cache/day2-single-node)
- Day 3 - Launch a HTTP Server [Code](gee-cache/day3-http-server)
- Day 4 - Consistent Hash Algorithm [Code](gee-cache/day4-consistent-hash)
- Day 5 - Communication between Distributed Nodes [Code](gee-cache/day5-multi-nodes)
- Day 6 - Cache Breakdown & Single Flight | [Code](gee-cache/day6-single-flight)
- Day 7 - Use Protobuf as RPC Data Exchange Type | [Code](gee-cache/day7-proto-buf)

## Object Relational Mapping - GeeORM

[GeeORM](https://geektutu.com/post/geeorm.html) is a [gorm](https://github.com/jinzhu/gorm)-like and [xorm](https://github.com/go-xorm/xorm)-like object relational mapping library

Xorm's desgin is easier to understand than gorm-v1, so the main designs references xorm and some detailed implementions references gorm-v1.

- Day 1 - database/sql Basic | [Code](gee-orm/day1-database-sql)
- Day 2 - Object Schame Mapping | [Code](gee-orm/day2-reflect-schema)
- Day 3 - Insert and Query | [Code](gee-orm/day3-save-query)
- Day 4 - Chain, Delete and Update | [Code](gee-orm/day4-chain-operation)
- Day 5 - Support Hooks | [Code](gee-orm/day5-hooks)
- Day 6 - Support Transaction | [Code](gee-orm/day6-transaction)
- Day 7 - Migrate Database | [Code](gee-orm/day7-migrate)

## RPC Framework - GeeRPC

[GeeRPC](https://geektutu.com/post/geerpc.html) is a [net/rpc](https://github.com/golang/go/tree/master/src/net/rpc)-like RPC framework

Based on golang standard library `net/rpc`, GeeRPC implements more features. eg, protocol exchange, service registration and discovery, load balance, etc.

- Day 1 - Server Message Codec | [Code](gee-rpc/day1-codec)
- Day 2 - Concurrent Client | [Code](gee-rpc/day2-client)
- Day 3 - Service Register | [Code](gee-rpc/day3-service )
- Day 4 - Timeout Processing | [Code](gee-rpc/day4-timeout )
- Day 5 - Support HTTP Protocol | [Code](gee-rpc/day5-http-debug)
- Day 6 - Load Balance | [Code](gee-rpc/day6-load-balance)
- Day 7 - Discovery and Registry | [Code](gee-rpc/day7-registry)

## Golang WebAssembly Demo

- Demo 1 - Hello World [Code](demo-wasm/hello-world)
- Demo 2 - Register Functions [Code](demo-wasm/register-functions)
- Demo 3 - Manipulate DOM [Code](demo-wasm/manipulate-dom)
- Demo 4 - Callback [Code](demo-wasm/callback)
Loading