RealIP
获取客户端的真实IP,先判断请求头是否有X-Forwarded-For
,如果没有再取X-Real-Ip
,都没有则从连接IP中取。
Example
package main
import (
"log"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewDefaultResponder())
e.GET("/", func(c *elton.Context) (err error) {
log.Println(c.RealIP())
c.Body = "Hello, World!"
return
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}