Skip to content

Commit 68ee275

Browse files
committed
新增获取GetRealIp 获取真实的ip地址
1 parent fa717cd commit 68ee275

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

serveMux.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package webapi
22

33
import (
4-
"github.com/farseer-go/collections"
5-
"github.com/farseer-go/fs/flog"
6-
"github.com/farseer-go/webapi/context"
7-
"github.com/farseer-go/webapi/middleware"
8-
"github.com/farseer-go/webapi/websocket"
94
"net"
105
"net/http"
116
"net/url"
127
"path"
138
"sort"
149
"strings"
1510
"sync"
11+
12+
"github.com/farseer-go/collections"
13+
"github.com/farseer-go/fs/flog"
14+
"github.com/farseer-go/webapi/context"
15+
"github.com/farseer-go/webapi/middleware"
16+
"github.com/farseer-go/webapi/websocket"
1617
)
1718

1819
type serveMux struct {
@@ -303,3 +304,12 @@ func appendSorted(es []*context.HttpRoute, e *context.HttpRoute) []*context.Http
303304
func GetHttpContext() *context.HttpContext {
304305
return context.RoutineHttpContext.Get()
305306
}
307+
308+
// GetRealIp 获取真实的ip地址
309+
func GetRealIp() string {
310+
httpCtx := GetHttpContext()
311+
if httpCtx == nil {
312+
return "127.0.0.1"
313+
}
314+
return httpCtx.URI.GetRealIp()
315+
}

0 commit comments

Comments
 (0)