Help us shape the future of Go! Take the 2026 Go Developer Survey

network

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package network 提供网络相关的轻量工具函数。

本包只包含 IP 地址解析与获取(IsPublicIP/GetPodIP 等)这类零依赖的 基础工具,供 registry、nns 等模块在解析注册地址时复用;HTTP 客户端 (httpx)、WebSocket(wsutil)、消息队列(nats/mq)等网络客户端见 github.com/oekit/network。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLanIPs

func GetLanIPs() ([]string, error)

GetLanIPs 获取局域网本地 IP 地址列表。

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP 返回本机首选非回环 IPv4 地址。 优先读取 POD_IP 环境变量(K8s 注入),其次遍历网卡获取第一个非回环 IPv4。 未找到时返回错误。这是 ekit 中获取本机 IP 的唯一实现, uidgen、nacos、registry 等包应委托至此,避免逻辑重复。

func GetPodIP

func GetPodIP() string

GetPodIP 返回本机 IP 地址(无 error 版本,适合无法处理 error 的注册场景)。 优先读取 POD_IP 环境变量,其次遍历网卡;失败时回退到 127.0.0.1。 这是 GetLocalIP 的便捷封装,uidgen、nacos、registry 应委托至此。

func GetServerIP

func GetServerIP() string

GetServerIP 返回服务器 IP,优先返回外网 IP。

func HostName

func HostName() string

HostName 返回主机名。

func IsIPv4

func IsIPv4(ip net.IP) bool

IsIPv4 判断是否是 IPv4 地址。

func IsPublicIP

func IsPublicIP(ip net.IP) bool

IsPublicIP 判断 IP 是否是公网 IP。

func ServerIP

func ServerIP() (externalIP, internalIP string)

ServerIP 返回服务器的外网 IP 和内网 IP。

func ServerIPString

func ServerIPString() string

ServerIPString 返回所有服务器 IP 的逗号分隔字符串。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL