MCPcopy Index your code
hub / github.com/1Panel-dev/KubePi / normalizeLoginIP

Function normalizeLoginIP

internal/api/v1/session/session.go:289–307  ·  view source on GitHub ↗
(remoteAddr string)

Source from the content-addressed store, hash-verified

287}
288
289func normalizeLoginIP(remoteAddr string) string {
290 ipValue := strings.TrimSpace(remoteAddr)
291 if host, _, err := net.SplitHostPort(ipValue); err == nil {
292 ipValue = host
293 }
294 ipValue = strings.Trim(ipValue, "[]")
295
296 parsedIP := net.ParseIP(ipValue)
297 if parsedIP == nil {
298 return ipValue
299 }
300 if parsedIP.IsLoopback() {
301 return loginIPLocalAddress
302 }
303 if ipv4 := parsedIP.To4(); ipv4 != nil {
304 return ipv4.String()
305 }
306 return parsedIP.String()
307}
308
309func getLoginIPArea(ipValue string) string {
310 parsedIP := net.ParseIP(ipValue)

Callers 2

TestNormalizeLoginIPFunction · 0.85
SaveLoginLogMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestNormalizeLoginIPFunction · 0.68