GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl 如果使用 go1.16 版本, 可以使用go install命令安装 GOPROXY=https://goproxy.cn/,directgo installhttp://github.com/tal-tech/go-zero/tools/goctl@latest 快速生成api服务 goctl api new gree...
将api中的路由添加到server中。 将路由注册到路由树上,并且启动服务 // 加载配置文件的路径varconfigFile=flag.String("f","etc/api-api.yaml","the etc file")funcinit(){//close statis loglogx.DisableStat()}funcmain(){flag.Parse()// c是自定义配置,其中包含了go-zero的默认配置varcconfig.Config/...
我们期望的是文档即协议,协议即服务,这个理念与go-zero的api定义不谋而合。 我们定义了BFF层,BFF是对外提供HTTP接口的统一出口,所以我们这里API的定义主要是针对BFF服务的API的定义。 API的兼容性 我们定义或修改API的时候一定要考虑向前兼容,如下几种情况是向前兼容的: 增加新的API接口协议 请求参数添加字段,需要保...
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get github.com/tal-tech/go-zero/tools/goctl ``` 创建工作目录shorturl 在shorturl目录下执行go mod init shorturl初始化go.mod 5. 编写API Gateway代码 通过goctl生成api/shorturl.api并编辑,为了简洁,去除了文件开头的info,代码如下: ```go ty...
go-zero 包含极简的 API 定义和生成工具 goctl,可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。 微服务需要: 概念 go-zero web和rpc框架 RPC 远程过程调用协议,RPC是两个进程的通信,可以跨设备,调用远程服务像调用本地应用程序一样。 api文件 ...
本文是对 使用go-zero快速构建微服务的亲手实践 编写API Gateway代码 mkdir bookstore && cd bookstore go mod init bookstore mkdir api && goctl api -o api/bookstore.api syntax = "v1" info( title: "xx使用go-zero" desc: "xx用来上手go-zero" author: "xxxx" email: "xxxx@gmail.com" ) typ...
简介: 使用go-zero快速构建微服务 编写API Gateway代码 mkdir bookstore && cd bookstore go mod init bookstore mkdir api && goctl api -o api/bookstore.api syntax = "v1" info( title: "xx使用go-zero" desc: "xx用来上手go-zero" author: "xxxx" email: "xxxx@gmail.com" ) type ( addReq...
代码语言:javascript 复制 git clone https://github.com/tal-tech/go-zero cd go-zero/tools/goctl go build goctl.go 最后生成goctl.exe 复制到Go的安装目录bin下 。 简单的使用方法: 代码语言:javascript 复制 goctl api go-api hello.api-dir. ...
go-zero 如何在api的中间件中调用rpc服务 需求场景 最近的开发过程中遇到一个场景,用go-zero开发的api服务中,除了login api外其他的api需要进行登录的认证(很普通的场景)。但由于整个后端架构是微服务模式,提供用户及登录验证的是另一个grpc服务。所以出现了需要在api的中间件中调用 用户rpc服务的问题。查了官网没...