RemoteAddr

获取请求客户端的IP,直接获取连接的客户端,不会从请求头中获取。

Example

  1. package main
  2. import (
  3. "log"
  4. "github.com/vicanso/elton"
  5. "github.com/vicanso/elton/middleware"
  6. )
  7. func main() {
  8. e := elton.New()
  9. e.Use(middleware.NewDefaultResponder())
  10. e.GET("/", func(c *elton.Context) (err error) {
  11. log.Println(c.RemoteAddr())
  12. c.Body = "Hello, World!"
  13. return
  14. })
  15. err := e.ListenAndServe(":3000")
  16. if err != nil {
  17. panic(err)
  18. }
  19. }