AttachRemoteIP adds any incoming IP data into the grpc context metadata
(ctx context.Context, r *http.Request)
| 539 | |
| 540 | // AttachRemoteIP adds any incoming IP data into the grpc context metadata |
| 541 | func AttachRemoteIP(ctx context.Context, r *http.Request) context.Context { |
| 542 | if ip, port, err := net.SplitHostPort(r.RemoteAddr); err == nil { |
| 543 | if intPort, convErr := strconv.Atoi(port); convErr == nil { |
| 544 | ctx = peer.NewContext(ctx, &peer.Peer{ |
| 545 | Addr: &net.TCPAddr{ |
| 546 | IP: net.ParseIP(ip), |
| 547 | Port: intPort, |
| 548 | }, |
| 549 | }) |
| 550 | } |
| 551 | } |
| 552 | return ctx |
| 553 | } |
| 554 | |
| 555 | // isIpWhitelisted checks if the given ipString is within the whitelisted ip range |
| 556 | func isIpWhitelisted(ipString string) bool { |
no outgoing calls
no test coverage detected