Skip to content

Commit

Permalink
新增获取GetRealIp 获取真实的ip地址
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jan 1, 2025
1 parent fa717cd commit 68ee275
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions serveMux.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package webapi

import (
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/webapi/context"
"github.com/farseer-go/webapi/middleware"
"github.com/farseer-go/webapi/websocket"
"net"
"net/http"
"net/url"
"path"
"sort"
"strings"
"sync"

"github.com/farseer-go/collections"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/webapi/context"
"github.com/farseer-go/webapi/middleware"
"github.com/farseer-go/webapi/websocket"
)

type serveMux struct {
Expand Down Expand Up @@ -303,3 +304,12 @@ func appendSorted(es []*context.HttpRoute, e *context.HttpRoute) []*context.Http
func GetHttpContext() *context.HttpContext {
return context.RoutineHttpContext.Get()
}

// GetRealIp 获取真实的ip地址
func GetRealIp() string {
httpCtx := GetHttpContext()
if httpCtx == nil {
return "127.0.0.1"
}
return httpCtx.URI.GetRealIp()
}

0 comments on commit 68ee275

Please sign in to comment.