[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.

在学习Golang中的gin框架的时候,遇到了下面的warning : 

[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.

对于上面的WARNING翻译出来之后也就是 : 您信任所有代理,这是不安全的。我们建议您设置一个值。

对于Goland编译器给出的建议  : 

Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-
proxies for details.

也就是去看文档去了解细节,额,好像又啥也没说!

那么怎么解决呢?

根据warning也就是给gin设置一个信任ip : 127.0.0.1

代码 : 

	router := gin.Default()
	router.SetTrustedProxies([]string{"127.0.0.1"})

猜你喜欢

转载自blog.csdn.net/ros275229/article/details/132221099