当前位置:网站首页>golang-gin-pprof-使用以及安全问题
golang-gin-pprof-使用以及安全问题
2022-07-31 13:01:00 【SakuraKizuna】
pprof是golang的提供的性能分析工具
直接通过引用github.com/gin-contrib/pprof即可调用
项目代码节选展示:
//性能调优监视 TODO Gin自主隐藏,待优化
authStr := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(config.ProducerUsername+":"+config.ProducerPassword)))
pprofGroup := r.Group("/producer", func(c *gin.Context) {
auth := c.Request.Header.Get("Authorization")
if auth != authStr {
c.Header("www-Authenticate", "Basic")
c.AbortWithStatus(http.StatusUnauthorized)
return
}
c.Next()
})
pprof.RouteRegister(pprofGroup, "flowerxxxxx_pprof")
Gin框架所携带的pprof直接调用即可,但是在生产环境中会引发暴露的问题,导致/debug/pprof接口暴露到公网。
我们将接口注册到新的路由组里,并且将(账号+冒号+密码)Base64后并添加Basic标识,即可触发访问也要输入账号和密码的保护机制。

项目(中小型)pprof分析概览,可查看是否存在goroutine死锁或者cpu异常占用问题。

边栏推荐
猜你喜欢

365天挑战LeetCode1000题——Day 044 最大层内元素和 层次遍历

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your

PyQt5 rapid development and actual combat 9.7 Automated testing of UI layer

C#控件ListView用法

CWE4.8 -- 2022年危害最大的25种软件安全问题

通过斐波那契数再谈函数递归2.0

系统集成项目管理工程师(软考中级)知识点总结【挣值分析】【关键路径】

Use docker to build mysql master-slave

函数递归1.0

关于MySQL主从复制的数据同步延迟问题
随机推荐
PyQt5快速开发与实战10.2 复利计算 && 10.3 刷新博客点击量
365天挑战LeetCode1000题——Day 044 最大层内元素和 层次遍历
Centos7 install mysql5.7 steps (graphical version)
ECCV2022:在Transformer上进行递归,不增参数,计算量还少!
立一个flag
分布式监视 Zabbix 和 Prometheus 到底怎么选?千万别用错了!
AMBA APB学习记录(AMBA 2.0)
CentOS7 installation MySQL graphic detailed tutorial
聊聊 SAP 产品 UI 上的消息显示机制
C#使用NumericUpDown控件
NameNode故障处理的两种方法
Google Chrome(谷歌浏览器)安装使用
集群的安全模式
这款悄然崛起的国产API接口管理工具,你一定要晓得
Cognitive-exercise rehabilitation medical robot application design
2022年最新重庆建筑安全员模拟题库及答案
行业案例 | 全面防护 赛宁助力能源工控安全建设
go中select语句
报错:npm ERR code EPERM
The cluster of safe mode