# go-zero 微服务实战 https://zhuanlan.zhihu.com/p/461604538 常用命令 mkdir -p mall && cd mall && go mod init mkdir -p service && cd service mkdir -p {user,order,pay,product}/{api,rpc,model} cd user goctl model mysql ddl -src ./model/user.sql -dir ./model -c goctl api go -api ./api/user.api -dir ./api goctl rpc protoc rpc/user.proto --go_out=./rpc/pb --go-grpc_out=./rpc/pb --zrpc_out=rpc/ goctl docker --go user.go --port 8000 cd ~/go-zero-demo/mall/service/product/api go mod init github.com/dfang/mall/service/product/api go mod tidy cd ~/go-zero-demo/mall/service/product/rpc go mod init github.com/dfang/mall/service/pay/rpc go mod tidy cd ~/go-zero-demo/mall/service/user/api go mod init github.com/dfang/mall/service/user/api go mod tidy cd ~/go-zero-demo/mall/service/user/rpc go mod init github.com/dfang/mall/service/pay/rpc go mod tidy cd ~/go-zero-demo/mall/service/order/api go mod init github.com/dfang/mall/service/order/api go mod tidy cd ~/go-zero-demo/mall/service/order/rpc go mod init github.com/dfang/mall/service/order/rpc go mod tidy cd ~/go-zero-demo/mall/service/pay/api go mod init github.com/dfang/mall/service/pay/api go mod tidy cd ~/go-zero-demo/mall/service/pay/rpc go mod init github.com/dfang/mall/service/pay/rpc go mod tidy gsed -i 's/search/replace/gI' input.txt # only find word ‘love’ and replace it with ‘sick’ if line content a specific string such as FOO: sed -i -e '/FOO/s/love/sick/' input.txt etcdctl get "" --prefix --keys-only etcdctl --endpoints etcd:2379 get "" --prefix --keys-only unset all proxy on local find . -name captain.yml -execdir captain build \; find . -name captain.yml -execdir sh -c "captain build; captain push" \; ``` λ tree -L 2 service/ service/ ├── order │ ├── api │ ├── captain.yml │ ├── model │ └── rpc ├── pay │ ├── api │ ├── captain.yml │ ├── model │ └── rpc ├── product │ ├── api │ ├── captain.yml │ ├── model │ └── rpc └── user ├── api ├── captain.yml ├── model └── rpc # 进入每个RPC目录执行go mod tidy λ find . -type d -iname rpc -execdir sh -c "cd {}; go mod tidy" \; cd service find . -name go.mod -execdir bash -c "go mod tidy" \; find . -iname .gitignore -execdir bash -c "cat {}; echo" \; find . -iname .gitignore -execdir bash -c "git add {}" \; ```