what how:
词汇分析: token list 语法分析: ast generate code ast tree what: token之间的关系, 用树形式表示出来
parse tree vs abstract tree: ast 是 parse tree 进一步提炼
go parse work how:
goToken: getTokenList parser: getAst rules the proces:
rules and datasources parse parse: bool 表达式
1 a < 9 && b > 0 logic ops: ||, && compare: >=, <=, != list:
https://github.com/Knetic/govaluate example: a > 1 && (b <10 || a < 199)
microservice framework: 提供工具以方便构建微服务,通常以rpc 通信为核心
framework basic tool:
service discovery: based on etcd,consual transport : based on grpc …. go zero 框架:
go-kit go-micro go-zero go-micro:
gateway-> aggregated service-> single service go zero architecture: 基于rpc封装;
api 聚合服务 rpc 单个服务 the component: api: 聚合服务 rpc:特定服务
服务注册发现
basic router: path, handler hander: srvContext,
arhitecture 框架特点:
controller service service.repo service.rpc rpc 框架
api handler-> logic: call rpc rpc servicesA servicesB rest server:
1 2 3 4 5 restServer = newServer() ctx = newContext(rpcClient) register(restServer, handler): restServer.
这一次,彻底掌握go mod
Semantic Import Versioning
go get; exact the path; clone the path to $GOPATH/src or $GOPATH/mod go 基于 git 构建仓库
git clone address: package tag: package version version name; v2.3.4: major:incompatiable minor: new feature; patch version: bug fix
伪版本: 不符合 v1.1.1格式; xxx—xxxxxxxxxxxxx
go.mod module name: github地址;
require: 直接引用的包
incompatiable: major>=2,但 path 不包含 …/vN indirect: 非直接依赖: current –> B–[direct]–>[C,D]; C, D indirect: B没有module管理, C,D 没有在B的 go.mod文件中 how to update major version update go get -u: update current module go.
basic operation op:
enqueue dequeue 1 2 #define size 5 int item[size] circular queue ![[Pasted image 20221121175921.png]]
op:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 var queueSize = 6 var header,tail = -1 var circularQ [queueSize]int isEmpty: front= -1 dequeue: if isEmpty, return; ele = circularQ[front] front = front++ mod queueSize; return ele also called: ring buffer
dequeue
the used case
load balance 1. what’s distribute a set of tasks(requests…) over a set of Nodes
[task1,task2, …]->[node1,node2,…]
target: make full use of every node
2. how? 1. round-robin 2. least connection/responseTime 3. ip hash
race condition
Data Races vs Race Conditions - Cronokirby - https://cronokirby.com/posts/2019/06/data-races-vs-race-conditions/data-races-vs-race-conditions/
data race and race condition race conditon 在并发的程序里
产生不确定行为,non-determinism 我们预期程序总是产生特定行为 1 2 3 4 5 6 7 8 9 10 func main() { go func() { for { fmt.Println("Thread B") } } for { fmt.Println("Thread A") } } 如果我们期望按照 threadA-threadb 交替输出,则是race conditon
data race 多个线程同时访问一个变量 至少有一个是写入操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 未获得预期的结果 1.