mirror of
https://github.com/wahyd4/badger.git
synced 2026-08-09 05:15:58 +10:00
30 lines
467 B
Go
30 lines
467 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
)
|
|
|
|
func GetUserIP(r *http.Request) string {
|
|
IPAddress := r.Header.Get("X-Real-Ip")
|
|
if IPAddress == "" {
|
|
IPAddress = r.Header.Get("X-Forwarded-For")
|
|
}
|
|
if IPAddress == "" {
|
|
IPAddress = r.RemoteAddr
|
|
}
|
|
return IPAddress
|
|
}
|
|
|
|
func DumpRequest(r *http.Request) {
|
|
if r == nil {
|
|
return
|
|
}
|
|
dump, err := httputil.DumpRequest(r, true)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
fmt.Println(dump)
|
|
}
|