clientip

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package clientip provides client IP helpers. Package clientip 提供客户端 IP 辅助函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromRemote

func FromRemote(remoteAddr string) (netip.Addr, bool)

FromRemote parses an IP from remoteAddr. FromRemote 从 remoteAddr 解析 IP。

func FromRequest

func FromRequest(r *http.Request, opts Options) (netip.Addr, bool)

FromRequest returns the client IP for r. Call FromRequest(r, Options{TrustedProxies: ...}) when forwarded headers are trusted. FromRequest 返回 r 的客户端 IP。 需要信任转发头时,调用 FromRequest(r, Options{TrustedProxies: ...})。

Example / 示例:

ip, ok := clientip.FromRequest(r, clientip.Options{})

Types

type Options

type Options struct {
	TrustedProxies []netip.Prefix
}

Options configures forwarded-header trust. Options 配置转发头信任边界。

Jump to

Keyboard shortcuts

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