当前位置:网站首页>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异常占用问题。
边栏推荐
- 全局平均池化层替代全连接层(最大池化和平均池化的区别)
- 分布式锁有哪些,怎么实现(分布式锁的三种实现的对比)
- 一文吃透哈希表
- ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
- C# 中的Async 和 Await 的用法详解
- 函数递归1.0
- ASM module in SAP Ecommerce Cloud Spartacus UI and Accelerator UI
- Encapsulation of conversion between Json and objects (Gson)
- PHP序列化:eval
- 2022年最新重庆建筑安全员模拟题库及答案
猜你喜欢
365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal
go中select语句
函数的参数
纷享销客罗旭对话元气森林黄晓枫:零售数字化的终点不是创新,而是数据
【CPU设计实战】简单流水线CPU设计
报错IDEA Terminated with exit code 1
NPM 使用介绍
一文吃透哈希表
SAP 电商云 Spartacus UI 和 Accelerator UI 里的 ASM 模块
NameNode (NN) and SecondaryNameNode (2NN) working mechanism
随机推荐
Centos7 install mysql5.7
Using SQL Server FOR XML and FOR JSON syntax on other RDBMSs with jOOQ
电脑重要文件很多,如何备份比较安全?
Architecture Camp | Module 8
Flutter keyboard visibility
深入浅出边缘云 | 4. 生命周期管理
NameNode故障处理的两种方法
AMBA APB学习记录(AMBA 2.0)
列表页优化思路
一文吃透哈希表
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]
求一份常见Oracle故障模拟场景
攻防演练丨赛宁红方管控平台走进广东三地 助力数字政府网络安全建设
2022年最新重庆建筑安全员模拟题库及答案
Structural controllability of switched linear systems with symmetry constraints
FastAPI 封装一个通用的response
JSP中如何借助response对象实现页面跳转呢?
知名无人驾驶公司:文远知行内推
Cognitive-exercise rehabilitation medical robot application design
Ali on three sides: MQ message loss, repetition, backlog problem, how to solve?