Skip to content

IP Address

c.RemoteIP() reads the peer address from Request.RemoteAddr. It does not trust forwarding headers.

peer := c.RemoteIP()

c.IP() can resolve a forwarded client address when proxy trust is configured:

cfg := zinc.DefaultConfig
cfg.ProxyHeader = "X-Forwarded-For"
cfg.TrustedProxies = []string{
"10.0.0.0/8",
"192.168.0.0/16",
}
app := zinc.NewWithConfig(cfg)
app.Get("/whoami", func(c *zinc.Context) error {
return c.JSON(zinc.Map{
"client": c.IP(),
"chain": c.IPs(),
"peer": c.RemoteIP(),
})
})

When no trusted proxy matches, Zinc falls back to the direct peer address.