request

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

README

server/webserver/request

Import path: github.com/InsideGallery/core/server/webserver/request

request contains Fiber request helpers for resolving client IP addresses.

Main APIs

  • ErrAddressIsNotValid: sentinel returned when an address cannot be parsed.
  • IsPrivateAddress(address): reports whether an IP address is loopback, private, or link-local unicast.
  • IPFromRequest(c fiber.Ctx): extracts the preferred client IP from X-Forwarded-For, X-Real-Ip, or Fiber's request IP.
  • IPStringFromRequest(c fiber.Ctx): returns the parsed IP string or falls back to c.IP().

Usage

app.Get("/", func(c fiber.Ctx) error {
	clientIP := request.IPStringFromRequest(c)

	return c.SendString(clientIP)
})

Operational Notes

IPFromRequest selects the first public address in X-Forwarded-For. If none is usable, it falls back to X-Real-Ip; without forwarding headers it parses c.IP() and strips a host port when present.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAddressIsNotValid = errors.New("address is not valid")

Functions

func IPFromRequest

func IPFromRequest(c fiber.Ctx) (net.IP, error)

IPFromRequest extracts the real client IP from a Fiber request.

func IPStringFromRequest added in v1.1.0

func IPStringFromRequest(c fiber.Ctx) string

IPStringFromRequest returns the request IP as a strings.

func IsPrivateAddress

func IsPrivateAddress(address string) (bool, error)

IsPrivateAddress checks whether address is loopback, private, or link-local.

Types

This section is empty.

Jump to

Keyboard shortcuts

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