Standard library / net/netip

netip.AddrFrom4()

Build an IPv4 value from exactly four octets. Expected stdout: '192.0.2.7\n'.

Formal Syntax & Structure

go syntaxgo
func AddrFrom4(addr [4]byte) Addr

Parameters & Attributes

NameTypeDescription
addr[4]byteAddress value or address bytes in the required representation.

Return Value

Addr

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/netip")
func main() { fmt.Println(netip.AddrFrom4([4]byte{192, 0, 2, 7})) }
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference