Skip to content

Commit cb9d72e

Browse files
authored
Merge pull request revel#1069 from revel/add-clientip-to-controller
Added a client ip into controller instance
2 parents be4c74c + 4b86cf9 commit cb9d72e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Controller struct {
2626
MethodType *MethodType // A description of the invoked action type.
2727
AppController interface{} // The controller that was instantiated.
2828
Action string // The fully qualified action name, e.g. "App.Index"
29+
ClientIP string // holds IP address of request came from
2930

3031
Request *Request
3132
Response *Response

server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ func handleInternal(w http.ResponseWriter, r *http.Request, ws *websocket.Conn)
5151
// TODO For now this okay to put logger here for all the requests
5252
// However, it's best to have logging handler at server entry level
5353
start := time.Now()
54+
clientIP := ClientIP(r)
5455

5556
var (
5657
req = NewRequest(r)
5758
resp = NewResponse(w)
5859
c = NewController(req, resp)
5960
)
6061
req.Websocket = ws
62+
c.ClientIP = clientIP
6163

6264
Filters[0](c, Filters[1:])
6365
if c.Result != nil {
@@ -76,7 +78,7 @@ func handleInternal(w http.ResponseWriter, r *http.Request, ws *websocket.Conn)
7678
// 2016/05/25 17:46:37.112 127.0.0.1 200 270.157µs GET /
7779
requestLog.Printf("%v %v %v %10v %v %v",
7880
start.Format(requestLogTimeFormat),
79-
ClientIP(r),
81+
clientIP,
8082
c.Response.Status,
8183
time.Since(start),
8284
r.Method,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy