岚天逸见

随笔分类 -  go / go-zero

grpc-go通过context传递额外数据
摘要:使用 ctx.Value 从 context 读取数据 // ValueFromIncomingContext returns the metadata value corresponding to the metadata // key from the incoming metadata if 阅读全文

posted @ 2024-02-19 10:07 岚天逸见 阅读(73) 评论(0) 推荐(0) 编辑

go-zero/grpc的rpc服务间传递额外数据
摘要:客户端: md := metadata.New(map[string]string{"signature": "0123456789", "timestamp": "2021-07-01 00:00:00"}) ctx := metadata.NewOutgoingContext(ctx, md) 阅读全文

posted @ 2024-02-18 23:04 岚天逸见 阅读(57) 评论(0) 推荐(0) 编辑

go-zero读取mysql部分字段
摘要:读取部分字段,使用函数 QueryRowPartialCtx 。 假设有如下一张表: CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ctime DATETIME); 要读取字段 ctime 值。 定义一 阅读全文

posted @ 2024-02-17 00:09 岚天逸见 阅读(48) 评论(0) 推荐(0) 编辑

go-zero开发入门-初始化cache.ClusterConf示例
摘要:cache.ClusterConf 的定义如下: // CacheConf is an alias of ClusterConf. type CacheConf = ClusterConf type ( // A ClusterConf is the config of a redis cluste 阅读全文

posted @ 2024-01-26 10:14 岚天逸见 阅读(77) 评论(0) 推荐(0) 编辑

go-zero配置DB的redis缓存
摘要:配置定义: # cat internal/config/config.go package config import ( "github.com/zeromicro/go-zero/rest" "github.com/zeromicro/go-zero/core/stores/cache" ) t 阅读全文

posted @ 2024-01-25 18:41 岚天逸见 阅读(178) 评论(0) 推荐(0) 编辑

go-zero开发入门之gateway深入研究1
摘要:创建一个 gateway 示例: // main.go package main import ( "flag" "fmt" "gateway/middleware" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go- 阅读全文

posted @ 2023-12-15 17:58 岚天逸见 阅读(184) 评论(0) 推荐(0) 编辑

go-zero目录结构和说明
摘要:. ├── code-of-conduct.md 行为准则 ├── CONTRIBUTING.md 贡献指南 ├── core 框架的核心组件 │ ├── bloom 布隆过滤器,用于检测一个元素是否在一个集合中 │ ├── breaker 熔断器,用于防止过多的请求导致系统崩溃 │ ├── cmd 阅读全文

posted @ 2023-12-15 10:06 岚天逸见 阅读(208) 评论(0) 推荐(0) 编辑

go-zero开发入门之网关往rpc服务传递数据2
摘要:go-zero 的网关服务实际是个 go-zero 的 API 服务,也就是一个 http 服务,或者说 rest 服务。http 转 grpc 使用了开源的 grpcurl 库,当网关需要往 rpc 服务传递额外的数据,比如鉴权数据的时候,通过 http 的 header 进行: func Aut 阅读全文

posted @ 2023-12-13 21:49 岚天逸见 阅读(292) 评论(0) 推荐(0) 编辑

go-zero开发入门之网关往rpc服务传递数据1
摘要:go-zero 的网关往 rpc 服务传递数据时,可以使用 headers,但需要注意前缀规则,否则会发现数据传递不过去,或者对方取不到数据。 go-zero 的网关对服务的调用使用了第三方库 grpcurl,入口函数为 InvokeRPC: grpcurl.InvokeRPC(r.Context( 阅读全文

posted @ 2023-12-12 18:59 岚天逸见 阅读(212) 评论(0) 推荐(0) 编辑

go-zero开发入门-API网关鉴权开发示例
摘要:本文是go-zero开发入门-API网关开发示例一文的延伸,继续之前请先阅读此文。 在项目根目录下创建子目录 middleware,在此目录下创建文件 auth.go,内容如下: // 鉴权中间件 package middleware import ( "context" "errors" "net 阅读全文

posted @ 2023-12-10 20:18 岚天逸见 阅读(319) 评论(0) 推荐(0) 编辑

go-zero开发入门-API服务开发示例
摘要:接口定义 定义 API 接口文件 接口文件 add.api 的内容如下: syntax = "v1" info ( title: "API 接口文件示例" desc: "演示如何编写 API 接口文件" author: "一见" date: "2023年12月07日" version: "v1" ) 阅读全文

posted @ 2023-12-08 11:03 岚天逸见 阅读(191) 评论(0) 推荐(0) 编辑

go-zero开发入门-API网关开发示例
摘要:开发一个 API 网关,代理 https://www.cnblogs.com/aquester/p/17882070.html 中的 RPC 服务。 网关完整源代码 // file: main.go package main import ( "flag" "fmt" "github.com/zer 阅读全文

posted @ 2023-12-08 10:13 岚天逸见 阅读(386) 评论(0) 推荐(0) 编辑

go-zero的etcd配置
摘要:实现代码在 core/discov/config.go 文件中: type EtcdConf struct { Hosts []string Key string ID int64 `json:",optional"` User string `json:",optional"` Pass stri 阅读全文

posted @ 2023-12-07 17:55 岚天逸见 阅读(173) 评论(0) 推荐(0) 编辑

go-zero开发入门-加法客服端示例
摘要:定义 RPC 接口文件 接口文件 add.proto 的内容如下: syntax = "proto3"; package add; // 当 protoc-gen-go 版本大于 1.4.0 时需加上 go_package,否则编译报错“unable to determine Go import p 阅读全文

posted @ 2023-12-07 15:14 岚天逸见 阅读(123) 评论(0) 推荐(0) 编辑

go-zero开发之安装etcd
摘要:本文只涉及 Linux 上的安装。 二进制安装 下载二进制安装包 #ETCD_VER=v3.4.28 ETCD_VER=v3.5.10 DOWNLOAD_URL=https://github.com/etcd-io/etcd/releases/download INSTALL_DIR=/tmp rm 阅读全文

posted @ 2023-12-06 23:11 岚天逸见 阅读(190) 评论(0) 推荐(0) 编辑

go-zero开发之安装goctl及go-zero开发依赖
摘要:安装 goctl go 版本在 1.16 及以后执行: GO111MODULE=on&&go install github.com/zeromicro/go-zero/tools/goctl@latest go 版本在 1.16 之前执行: GO111MODULE=on&&go get -u git 阅读全文

posted @ 2023-12-06 22:44 岚天逸见 阅读(332) 评论(0) 推荐(0) 编辑

导航

统计信息

点击右上角即可分享
微信分享提示