# go-micro-user **Repository Path**: llqhz/go-micro-user ## Basic Information - **Project Name**: go-micro-user - **Description**: micro 基础入门示例 - **Primary Language**: Go - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-15 - **Last Updated**: 2022-01-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [TOC] # micro 工具使用 ## 1. 创建模板 ```shell # 拉取镜像 docker pull micro/micro # 生成project docker run --rm -v $(pwd):$(pwd) -w $(pwd) micro/micro new user ``` ```shell # 创建目录 domain - model - repository - model ``` ## 安装依赖 ```shell go mod init gitee.com/llqhz/go-micro-user/user go mod tidy && go mod vendor ``` #### 私有库 export GOPRIVATE="*.gitee.com" > go get xxx 使用的是 git clone 命令, 默认只支持公有仓库 > 通过替换 https 为 ssh 请求, 可以免登录clone 私有仓库, 达到 go get 私有包的目的 > ```shell git config --global url."git@gitee.com/".insteadOf "https://gitee.com/" ``` ## 2. protoc 0. 修改和定义 proto文件 1. 安装protoc https://github.com/google/protobuf/releases/tag/v3.4.1 2. 安装 proto,gen-proto-go, go get -u github.com/golang/protobuf/proto go get -u github.com/golang/protobuf/protoc-gen-go go install github.com/micro/micro/v3/cmd/protoc-gen-micro 3. 生成文件 cd user protoc -I . --go_out=. --micro_out=. proto/user/user.proto > 定义proto时,变量名使用小写+下划线, 生成代码时,会自动转为大驼峰形式 ## 3. 开发model,repository,service, handle > command + N 生成接口的实现代码 > command + alt + v 生成方法返回值 > ctrl + command + / 生成方法注释 ## 4. 注册服务 main.go 开发