fix: algo on geting ip

master
Evan Chen 2021-10-19 00:47:09 +08:00
parent aa3d4a1615
commit 5e8c3bd70a
1 changed files with 4 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"net"
"net/http"
"os"
"strings"
"time"
"github.com/spf13/cobra"
@ -70,7 +71,9 @@ func StartServer() error {
func GetIP(r *http.Request) string {
ip := r.Header.Get("X-Real-Ip")
if ip == "" {
ip = r.Header.Get("X-Forwarded-For")
ips := r.Header.Get("X-Forwarded-For")
ipArr := strings.Split(ips, ",")
ip = strings.Trim(ipArr[len(ipArr)-1], " ")
}
if ip == "" {
var err error