上一页 1 2 3 4 5 6 7 ··· 53 下一页

2025年6月21日

go context value保存map

摘要: go context虽然只能保存一对key和value,但是支持any;虽然获取value时支持不断从父context中找,但是无法获取所有kv。 package main import ( "maps" "context" "fmt" ) // context推荐使用自定义结构体类型作为key,与 阅读全文

posted @ 2025-06-21 11:00 王景迁 阅读(13) 评论(0) 推荐(0)

2025年6月20日

go https代理认证

摘要: curl --proxy-header "代理认证信息" --proxy "代理地址" https://xxx 这里--proxy-header和普通header -H不等价,虽然两者类型相同,但是前者只发送给代理服务端(仅限https场景),后者只发送给服务端。 go Transport实现了ht 阅读全文

posted @ 2025-06-20 22:04 王景迁 阅读(14) 评论(0) 推荐(0)

2025年6月17日

grpc常见报错

摘要: 报错1:rpc error:code=DeadlineExceeded desc = context deadline exceeded原因:客户端context超时时间小于服务端响应时间。解决:gRPC客户端建议显式指定超时时间,延长客户端超时时间。 ctx, cancel := context. 阅读全文

posted @ 2025-06-17 09:08 王景迁 阅读(62) 评论(0) 推荐(0)

2025年6月15日

iptables规则中配置ipset

摘要: # 创建ipset ipset create white-list hash:ip ips="10.0.0.1,10.0.0.2,10.0.0.3" # 根据逗号切割 ipArr=(${ips//\,/ }) for item in "${ipArr[@]}" do # 增加单个ip ipset a 阅读全文

posted @ 2025-06-15 21:43 王景迁 阅读(34) 评论(0) 推荐(0)

2025年6月9日

Linux 查看最近一次系统启动时间

摘要: who -b uptime -s 阅读全文

posted @ 2025-06-09 08:38 王景迁 阅读(23) 评论(0) 推荐(0)

2025年6月7日

Linux sync同步数据到磁盘

摘要: 先创建好文件a.log内容是test2,再执行以下脚本。 echo "test3" > a.log cat a.log # 触发系统崩溃重启 bash -c "echo c > /proc/sysrq-trigger" 发现重启后还是test2。 触发系统崩溃重启前执行sync,保证文件内容是tes 阅读全文

posted @ 2025-06-07 18:46 王景迁 阅读(30) 评论(0) 推荐(0)

go 基于不同Host访问不同服务

摘要: 不同于其他语言,go语言通过request.Host字段来指定主机域名,而不是headers里面"Host"。在Nginx中,server_name对应http请求中的Host。 docker run --network host -d nginx:1.23 # 修改配置文件 vim /etc/ng 阅读全文

posted @ 2025-06-07 17:31 王景迁 阅读(21) 评论(0) 推荐(0)

2025年5月31日

go 基于beego+swagger生成支持直接调用的接口文档

摘要: 安装工具 go get github.com/astaxie/beego go get github.com/beego/bee 创建API项目 # 必须在GOPATH下创建项目,否则无法在routers目录下生成commentsRouter_controllers.go,访问URL会报错404 c 阅读全文

posted @ 2025-05-31 23:04 王景迁 阅读(19) 评论(0) 推荐(0)

go 单元测试使用assert

摘要: package test import ( "testing" "github.com/stretchr/testify/assert" ) func TestSomething(t *testing.T) { a := "a" b := "b" // a是expected // b是actual 阅读全文

posted @ 2025-05-31 20:21 王景迁 阅读(22) 评论(0) 推荐(0)

2025年5月30日

coredns配置外部dns服务器

摘要: kubectl edit cm coredns -n kube-system # ConfigMap coredns默认配置 # 非k8s域名通过宿主机上/etc/resolv.conf解析 forward . /etc/resolv.conf { max_concurrent 1000 } # 自 阅读全文

posted @ 2025-05-30 09:07 王景迁 阅读(77) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 53 下一页

导航