sqlip

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sqlip provides database/sql Scanner/Valuer types for IP data. Standard library only — works with any driver (pgx stdlib, lib/pq, go-sql-driver/mysql, sqlite).

  • Addr: PostgreSQL inet (host), or any text column.
  • Prefix: PostgreSQL cidr/inet (network), or any text column.
  • BinaryAddr: MySQL VARBINARY(16) / INET6_ATON form (4 or 16 bytes).

The zero value of each type maps to SQL NULL. Scanned addresses are normalized (IPv4-mapped IPv6 unmapped).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

type Addr struct{ netip.Addr }

Addr is a nullable IP address stored as text.

func (*Addr) Scan

func (a *Addr) Scan(src any) error

Scan accepts text only ("10.0.0.1", Postgres inet "10.0.0.1/32"), as string or []byte. Raw binary columns need BinaryAddr: 16 bytes of text such as "2001:db8::1:2:34" would otherwise be indistinguishable.

func (Addr) Value

func (a Addr) Value() (driver.Value, error)

Value returns the text form, or nil for the zero Addr.

type BinaryAddr

type BinaryAddr struct{ netip.Addr }

BinaryAddr is a nullable IP address stored as 4 (IPv4) or 16 (IPv6) bytes.

func (*BinaryAddr) Scan

func (b *BinaryAddr) Scan(src any) error

Scan accepts NULL or exactly 4 or 16 raw bytes.

func (BinaryAddr) Value

func (b BinaryAddr) Value() (driver.Value, error)

Value returns the raw bytes, or nil for the zero BinaryAddr.

type Prefix

type Prefix struct{ netip.Prefix }

Prefix is a nullable network stored as text. Host bits are masked on scan, so Postgres inet values like 10.1.2.3/8 become 10.0.0.0/8.

func (*Prefix) Scan

func (p *Prefix) Scan(src any) error

Scan accepts CIDR text or a bare address (becoming /32 or /128).

func (Prefix) Value

func (p Prefix) Value() (driver.Value, error)

Value returns the CIDR text, or nil for the zero Prefix.

Jump to

Keyboard shortcuts

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