18 lines
273 B
Go
18 lines
273 B
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
type PublicService struct {
|
|
}
|
|
|
|
// GetUserIP 获取用户ip
|
|
func (r *PublicService) GetUserIP(h *http.Request) string {
|
|
forwarded := h.Header.Get("X-FORWARDED-FOR")
|
|
if forwarded != "" {
|
|
return forwarded
|
|
}
|
|
return h.RemoteAddr
|
|
}
|