dengbiao 1 semana atrás
pai
commit
1d515951f6
2 arquivos alterados com 5 adições e 1 exclusões
  1. +1
    -1
      app/hdl/hdl_demo.go
  2. +4
    -0
      app/utils/ip.go

+ 1
- 1
app/hdl/hdl_demo.go Ver arquivo

@@ -26,7 +26,7 @@ import (
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/test [GET]
func Demo(c *gin.Context) {
fmt.Println("headers::::", c.Request.Header)
fmt.Println("headers::::", utils.GetIP(c.Request))
utils.FilePutContents("headers", utils.SerializeStr(c.Request.Header))
var args interface{}
if c.Request.Method == "GET" {


+ 4
- 0
app/utils/ip.go Ver arquivo

@@ -72,6 +72,10 @@ func ClientIP(r *http.Request) string {
// 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func ClientPublicIP(r *http.Request) string {
var ip string
if ip = strings.TrimSpace(r.Header.Get("Ali-Cdn-Real-Ip")); ip != "" {
return ip
}

for _, ip = range strings.Split(r.Header.Get("X-Forwarded-For"), ",") {
if ip = strings.TrimSpace(ip); ip != "" && !HasLocalIPAddr(ip) {
return ip


Carregando…
Cancelar
Salvar